Created
December 23, 2020 15:39
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>
</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