Skip to content

Instantly share code, notes, and snippets.

@grahamc
Created December 11, 2018 17:03
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 grahamc/0e2cd6cf3ba89b3237fb3530670d9f36 to your computer and use it in GitHub Desktop.
Save grahamc/0e2cd6cf3ba89b3237fb3530670d9f36 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet [
]>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:d="http://docbook.org/ns/docbook"
version="1.0">
<xsl:output method="text" encoding="UTF-8" />
<xsl:variable name="newline">
<xsl:text>&#xa;</xsl:text>
</xsl:variable>
<xsl:template match="d:literal">
<xsl:text>`</xsl:text>
<xsl:value-of select="." />
<xsl:text>`</xsl:text>
</xsl:template>
<xsl:template match="d:emphasis">
<xsl:text>*</xsl:text>
<xsl:value-of select="." />
<xsl:text>*</xsl:text>
</xsl:template>
<xsl:template match="d:book">
<xsl:for-each select="d:info">
<xsl:if test="d:title">
<xsl:text># </xsl:text>
<xsl:value-of select="d:title"/>
<xsl:value-of select="$newline" />
</xsl:if>
<xsl:if test="d:subtitle">
<xsl:text>## </xsl:text>
<xsl:value-of select="d:subtitle"/>
<xsl:value-of select="$newline" />
</xsl:if>
</xsl:for-each>
<xsl:for-each select="d:preface">
<xsl:if test="d:title">
<xsl:text># </xsl:text>
<xsl:value-of select="d:title"/>
<xsl:value-of select="$newline" />
</xsl:if>
<xsl:if test="d:subtitle">
<xsl:text>## </xsl:text>
<xsl:value-of select="d:subtitle"/>
<xsl:value-of select="$newline" />
</xsl:if>
<xsl:for-each select="d:para">
<xsl:value-of select="normalize-space(.)"/>
<xsl:value-of select="$newline" />
<xsl:value-of select="$newline" />
</xsl:for-each>
</xsl:for-each>
<xsl:value-of select="$newline" />
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment