File: Data.xml
<story>
<chapter>
<title>Chapter 1</title>
<para>para 1</para>
<para>item 1</para>
</chapter>
</story>
File: Transform.xslt
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:template match="chapter">
<xsl:variable name="chapNum">
<xsl:number />
</xsl:variable>
<xsl:document href="chap{$chapNum}.html">
<html>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:document>
</xsl:template>
<xsl:template match="chapter/title">
<h1>
<xsl:apply-templates />
</h1>
</xsl:template>
<xsl:template match="para">
<p>
<xsl:apply-templates />
</p>
</xsl:template>
</xsl:stylesheet>
Output:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="chapter">
<xsl:variable name="chapNum">
<xsl:number/>
</xsl:variable>
<xsl:document href="chap{$chapNum}.html">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:document>
</xsl:template>
<xsl:template match="chapter/title">
<h1>
<xsl:apply-templates/>
</h1>
</xsl:template>
<xsl:template match="para">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
</xsl:stylesheet>
|