Skip to content

Instantly share code, notes, and snippets.

@ColinMaudry
Last active March 2, 2016 19:39
Show Gist options
  • Select an option

  • Save ColinMaudry/f45c481c878f6d131e79 to your computer and use it in GitHub Desktop.

Select an option

Save ColinMaudry/f45c481c878f6d131e79 to your computer and use it in GitHub Desktop.
Replacing tabs characters in DITA codeblocks with spaces for PDF (FOP support)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.0"
exclude-result-prefixes="xs">
<xsl:template match="*[contains(@class,' pr-d/codeblock ')]">
<xsl:call-template name="generateAttrLabel"/>
<fo:block xsl:use-attribute-sets="codeblock">
<xsl:call-template name="commonattributes"/>
<xsl:call-template name="setFrame"/>
<xsl:call-template name="setScale"/>
<xsl:variable name="codeblock.line-number" as="xs:boolean">
<xsl:apply-templates select="." mode="codeblock.generate-line-number"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$codeblock.wrap or $codeblock.line-number">
<xsl:variable name="content" as="node()*">
<xsl:call-template name="codetext"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$codeblock.line-number">
<xsl:variable name="buf" as="document-node()">
<xsl:document>
<xsl:processing-instruction name="line-number"/>
<xsl:apply-templates select="$content" mode="codeblock.line-number"/>
</xsl:document>
</xsl:variable>
<xsl:variable name="line-count" select="count($buf/descendant::processing-instruction('line-number'))"/>
<xsl:apply-templates select="$buf" mode="codeblock">
<xsl:with-param name="line-count" select="$line-count" tunnel="yes"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:message>Otherwise...</xsl:message>
<xsl:apply-templates select="$content" mode="codeblock"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="codetext"/>
</xsl:otherwise>
</xsl:choose>
</fo:block>
</xsl:template>
<xsl:template match="*[contains(@class,' pr-d/codeblock ')]/text()" name="codetext">
<xsl:value-of select="replace(.,'&#009;',' ')"/>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment