<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE book
PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "docbookx.dtd">
<book>
<title>Financial Plan</title>
<chapter>
<title>Introduction</title>
<section>
<title>Overview</title>
<para>
After presenting educational planning recommendations for your
children's college needs, we will review ways to reach your
retirement objectives.
</para>
</section>
</chapter>
</book>
Listing 2 XML input data
<?xml version="1.0" encoding="utf-8"?>
<customer>
<name>John Doe</name>
<age>52</age>
<netWorth>2000000</netWorth>
<!-- other customer data -->
</customer>
Listing 3 XSLT transformation from input data to output document
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output doctype-public="-//OASIS//DTD DocBook XML V4.1.2//EN"/>
<xsl:output doctype-system="docbookx.dtd"/>
<xsl:template match="/">
<book>
<title>Financial Plan for <xsl:value-of select="customer/name"/>
</title>
<chapter>
<title>Introduction</title>
<section>
<title>Overview</title>
<para>
After presenting educational planning recommendations for
your children's college needs, we will review ways to
reach your retirement objectives
<xsl:text/>
<xsl:if test="customer/age > 50
and customer/netWorth > 500000">
and suggest estate planning techniques for minimizing tax
exposure<xsl:text/>
</xsl:if>.
</para>
</section>
</chapter>
</book>
</xsl:template>
</xsl:stylesheet>
Listing 4 Output document in DocBook
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "docbookx.dtd">
<book>
<title>Financial Plan for John Doe</title>
<chapter>
<title>Introduction</title><section>
<title>Overview</title>
<para>
After presenting educational planning recommendations for your
children's college needs, we will review ways to reach your
retirement objectives and suggest estate planning techniques
for minimizing tax exposure.
</para>
</section>
</chapter>
</book>
Listing 5 XSLT documentation generator
01 <?xml version="1.0" encoding="iso-8859-1"?>
02 <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
03 version="1.0">
04 <xsl:output doctype-public="-//OASIS//DTD DocBook XML V4.1.2//EN"/>
05 <xsl:output doctype-system="docbookx.dtd"/>
06 <xsl:strip-space elements="*"/>
07 <xsl:template match="xsl:template|xsl:stylesheet|xsl:text">
08 <xsl:apply-templates/>
09 </xsl:template>
10 <xsl:template match="xsl:output"></xsl:template>
11 <xsl:template match="xsl:value-of">
12 <xsl:text>[</xsl:text>
13 <xsl:call-template name="mapToBetterName">
14 <xsl:with-param name="nameIn" select="./@select"/>
15 </xsl:call-template>
16 <xsl:text>]</xsl:text>
17 </xsl:template>
18 <xsl:template match="xsl:if">
19 <xsl:text>[IF (</xsl:text>
20 <xsl:call-template name="mapToBetterName">
21 <xsl:with-param name="nameIn" select="./@test"/>
22 </xsl:call-template>)
23 <xsl:apply-templates/>
24 <xsl:text>]</xsl:text>
25 </xsl:template>
26 <xsl:template match="*">
27 <xsl:copy>
28 <xsl:copy-of select="@*"/>
29 <xsl:apply-templates/>
30 </xsl:copy>
31 </xsl:template>
32 <xsl:include href="mapnames.xsl"/>
33 </xsl:transform>
Listing 6 XSL variable mapping
<?xml version="1.0" encoding="utf-8"?>
<namemaps>
<namemap from="customer/age">customer's age</namemap>
<namemap from="customer/netWorth">customer's net worth
</namemap>
<!-- other mappings -->
</customer>
Listing 7 Generated documentation in DocBook
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"docbookx.dtd">
<book xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<title>Financial Plan for [customer's name]</title>
<chapter>
<title>Introduction</title>
<section>
<title>Overview</title>
<para>
After presenting educational planning recommendations for your
children's college needs, we will review ways to reach your
retirement objectives[IF (customer's age > 50 and
customer's net worth > 500000) and suggest estate planning
techniques for minimizing tax exposure].
</para>
</section>
</chapter>
</book>