Skip to content

Instantly share code, notes, and snippets.

@infotexture
Created April 23, 2012 21:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infotexture/2473924 to your computer and use it in GitHub Desktop.
Save infotexture/2473924 to your computer and use it in GitHub Desktop.
DITA-OT Customization: Numbered Headings in PDF output
<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version="2.0" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
Numbered Headings in PDF output per <http://tech.groups.yahoo.com/group/dita-users/message/26819>, 26827, 26828 & 26794
Template created via DITA-OT PDF plug-in generator <http://dita-generator.appspot.com/pdf-plugin> by Jarno Elovirta -->
<xsl:template match="*" mode="getTitle">
<xsl:variable name="topic" select="ancestor-or-self::*[contains(@class, &apos; topic/topic &apos;)][1]" />
<xsl:variable name="id" select="$topic/@id" />
<xsl:variable name="mapTopics" select="key(&apos;map-id&apos;, $id)" />
<fo:inline>
<xsl:for-each select="$mapTopics[1]">
<xsl:choose>
<xsl:when test="parent::opentopic:map" />
<xsl:when test="ancestor-or-self::*[contains(@class, &apos; bookmap/frontmatter &apos;) or contains(@class, &apos; bookmap/backmatter &apos;)]" />
<xsl:when test="ancestor-or-self::*[contains(@class, &apos; bookmap/appendix &apos;)]">
<xsl:number count="*[contains(@class, &apos; map/topicref &apos;)] [ancestor-or-self::*[contains(@class, &apos; bookmap/appendix &apos;)]]" format="A.1.1" level="multiple" />
</xsl:when>
<xsl:otherwise>
<xsl:number count="*[contains(@class, &apos; map/topicref &apos;)] [not(ancestor-or-self::*[contains(@class, &apos; bookmap/frontmatter &apos;)])]" format="1.1" level="multiple" />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</fo:inline>
<xsl:text> </xsl:text>
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
@qeaglin
Copy link

qeaglin commented May 17, 2012

I saw your post on the dita-users yahoo group and am trying to implement this code, so i can get numbered headings. Aside from adding this code to a custom file or the custom.xsl file (as the plugin generator does), what other customizations are required? I added the code to my /fo/xsl/custom.xsl file and got the following error when I attempted run my XEP transform:

[java] Error at xsl:when on line 13 column 62 of custom.xsl:
[java] XPST0081 XPath syntax error at char 21 on line 13 in {parent::opentopic:map}:
[java] Undeclared namespace prefix {opentopic}
[java] Failed to compile stylesheet. 1 error detected.

Do you know what and where I need to make a declaration?

TIA,
Qiana

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment