Skip to content

Instantly share code, notes, and snippets.

@econandrew
Created December 23, 2020 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save econandrew/e0b5bd1575baeec24e7a487324ced859 to your computer and use it in GitHub Desktop.
Save econandrew/e0b5bd1575baeec24e7a487324ced859 to your computer and use it in GitHub Desktop.
An XSLT template to extract comments from a Wordpress export XML file to a YAML-headed markdown file for Jekyll
<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wp="http://wordpress.org/export/1.2/" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select="rss/channel/item">
<xsl:variable name="vName" select="wp:post_name"/>
<xsl:variable name="vLink" select="link"/>
<xsl:variable name="vDate" select="wp:post_date"/>
<xsl:variable name="vPath" select="concat(fn:substring($vDate,1,10),'-',$vName)"/>
<xsl:for-each select="wp:comment">
<xsl:variable name="vWPID" select="wp:comment_id"/>
<xsl:result-document href="../andrewwhitby.com/_comments/{$vWPID}.md" method="text">---
path: <xsl:value-of select="$vPath"/>
slug: <xsl:value-of select="$vName"/>
link: <xsl:value-of select="$vLink"/>
wpid: <xsl:value-of select="wp:comment_id"/>
wptype: <xsl:value-of select="wp:comment_type"/>
parent_wpid: <xsl:value-of select="wp:comment_parent"/>
author: "<xsl:value-of select="wp:comment_author"/>"
author_url: <xsl:value-of select="wp:comment_author_url"/>
email: <xsl:value-of select="wp:comment_author_email"/>
date: <xsl:value-of select="wp:comment_date_gmt"/>
---
<xsl:value-of select="wp:comment_content"/>
<xsl:text>&#xa;</xsl:text>
</xsl:result-document>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment