Skip to content

Instantly share code, notes, and snippets.



Last active Mar 29, 2020
What would you like to do?
Generate a Single Page document containing all TOC Pages in a FHIR IG
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=""
<!-- This stylesheet should be pointed to the toc.html page
created by your IG build. It will process that table of contents
entries in that file to generate a single page html file which
can subsequently be used to generate a pdf.
<xsl:template match="/">
<xsl:call-template name='readtoc'/>
<!-- this template identifies the links,and passes them off to the process-toc template for handling -->
<xsl:template name="readtoc">
<!-- Put the page header at the top of the document -->
<xsl:copy-of select="//html:div[@id='segment-header']"/>
<!-- And the history note -->
<xsl:copy-of select="//html:p[@id='publish-box']"/>
<!-- Then copy the pages in the TOC in order -->
<xsl:apply-templates select="//html:div[@id='segment-content']//html:a" mode="process-toc"/>
<!-- Put the page footer at the bottom of the document -->
<xsl:copy-of select="//html:div[@id='segment-footer']"/>
<!-- read the filee into a document. This is why you need TIDY, because the XHTML
isn't QUITE XHTML (though it is remarkably close). -->
<xsl:template match="html:a" mode="process-toc">
<xsl:variable name="doc" select="document(@href)"/>
<xsl:apply-templates select="$doc//html:div[@id='segment-content']" mode="copy"/>
<!-- do nothing with the publish box in copy mode we already handled it -->
<xsl:template match="*[@id='publish-box']" mode="copy"/>
<!-- Try to fix up @hrefs in links. Eventually, this should be applied
to other stuff to, but this is simply a starter -->
<xsl:template match="@href" mode="copy">
<xsl:when test="contains(.,':') or starts-with(.,'/')">
<xsl:when test="contains(., '#')">
<xsl:attribute name="href">
<xsl:value-of select='concat("#", substring-after(.,"#"))'/>
<xsl:attribute name="href">
<xsl:value-of select='"#"'/>
<!-- And the copy template just passes everything else on through -->
<xsl:template match="@*|node()" mode="copy">
<xsl:apply-templates select="@*|node()" mode="copy"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.