Forum Moderators: open

Message Too Old, No Replies

Multiple html from XML file using XSLT

         

Chandru

7:40 am on May 22, 2008 (gmt 0)

10+ Year Member




I have the following XML file
<chapter id="A12">
<title id="T12">
<-- some data -->
</title>
<section id="S121">
<-- some data -->
</section>
<section id="S122">
<-- some data -->
</section>
<section id="S123">
<-- some data -->
</section>
</chapter>

Please let me know how do I generate separate html pages using XSLT for each child node of the parent "chapter".

The following code just retrieves a subset of XML pages

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:for-each select="chapter/section">
<xsl:result-document href="./outputExe/Chap1Section{position()}.htm">
<html>
<body>
<xsl:copy-of select="*"/>
</body>
</html>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
<xsl:template match="text()¦@*"/>
</xsl:stylesheet>

Thanks in advance chandru

httpwebwitch

7:31 pm on May 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try applying this to your XML:

<?xml version="1.0" encoding="iso-8859-1"?> 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:variable name="section">[red][b]S123[/b][/red]</xsl:variable>
<xsl:template match="/">
<html>
<body>
<xsl:copy-of select="chapter/section[@id=$section]"></xsl:copy-of>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

you can pass the section ID into your XSL as a parameter, and serve multiple pages that show only one section each