Skip to content

Commit 2497ea6

Browse files
author
Jason Porter
committed
Adding the xslt for conversion
Signed-off-by: Jason Porter <jporter@ibm.com>
1 parent 352bd03 commit 2497ea6

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

breakout-subsections.xslt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3+
<!-- Compose the XML and DOCTYPE declarations for the main output: -->
4+
<xsl:output encoding="utf-8" method="xml" doctype-system="topic.dtd" doctype-public="-//OASIS//DTD DITA Topic//EN"
5+
indent="yes"/>
6+
7+
<!-- Same output for the subsections, not sure if there's an easy way to reference this -->
8+
<xsl:output name="sub-section" indent="yes" method="xml" doctype-system="topic.dtd"
9+
doctype-public="-//OASIS//DTD DITA Topic//EN" encoding="utf-8"/>
10+
11+
<xsl:variable name="file-extension" select="'.dita'" />
12+
13+
<xsl:strip-space elements="*" />
14+
<xsl:preserve-space elements="codeblock pre screen" />
15+
16+
<!-- Fix up any xref links that reference adoc documents
17+
since adoc will not be used after the dita conversion -->
18+
<xsl:template match="//xref[contains(@href, '.adoc')]">
19+
<xref href="{replace(@href, '.adoc', '.dita')}"><xsl:value-of select="text()" /></xref>
20+
</xsl:template>
21+
22+
<!--
23+
Sections cannot be nested in DITA, but you can do a content reference.
24+
This splits out the nested section into its own topic file and creates a conref in the original document.
25+
The new subsection file will be created alongside the original with the id of the current topic and the
26+
subsection concatenated together.
27+
-->
28+
<xsl:template match="/topic/body/section//section">
29+
<xsl:variable name="sub-section-filename" select="concat(ancestor::topic/@id, @id, $file-extension)" />
30+
<div conref="{$sub-section-filename}">
31+
<xsl:value-of select="@id" />
32+
</div>
33+
<xsl:result-document href="{$sub-section-filename}" format="sub-section">
34+
<topic id="{@id}">
35+
<xsl:copy-of select="title" />
36+
<body>
37+
<xsl:apply-templates select="node()" />
38+
</body>
39+
</topic>
40+
</xsl:result-document>
41+
</xsl:template>
42+
43+
<!-- Don't need the title to be added in a subsection -->
44+
<xsl:template match="//section[position() > 1]/title"/>
45+
46+
<!-- Perform identity transformation -->
47+
<xsl:template match="@*|node()">
48+
<xsl:copy>
49+
<xsl:apply-templates select="@*|node()" />
50+
</xsl:copy>
51+
</xsl:template>
52+
53+
</xsl:stylesheet>

0 commit comments

Comments
 (0)