Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Tip: Create Multiple Files in XSLT 2.0

By Jack Herrington
2005-05-16


Get better output

It seems somehow counterintuitive that the contents of the xsl:result-document tag are evaluated in the same way as the rest of the template, but they are. And all the variables within the template context are available.

To demonstrate this, I've upgraded the code within the xsl:result-document tag to provide more information about the results of the test (see Listing 4).

Listing 4. Better HTML output from the template


<xsl:result-document href="{$filename}" format="html">
<html><head>
<title>Test results - <xsl:value-of select="@run"/></title>
</head><body>
<xsl:value-of select="@run"/> <!-- Run -->
<table>
<tr><td>Test</td><td>Pass</td></tr>
<xsl:for-each select="test">
<tr><td>
<xsl:value-of select="@name" />
</td><td>
<xsl:value-of select="@pass" />
</td></tr>
</xsl:for-each>
</table>
</body></html>
</xsl:result-document>

See Listing 5 for the HTML result of this output.

Listing 5. The upgraded HTML output


<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8">

<title>Test results - test1</title>
</head>
<body>
<!-- Run: test1-->
<table>
<tr>
<td>Test</td>
<td>Pass</td>
</tr>
<tr>
<td>foo</td>
<td>true</td>
</tr>
<tr>
<td>bar</td>
<td>true</td>
</tr>
<tr>
<td>baz</td>
<td>true</td>
</tr>
</table>
</body>
</html>


Tutorial Pages:
» Use a single XSLT template to create multiple files
» Create a file for each test
» Get better output
» Create an index
» Summary
» Resources


First published by IBM DeveloperWorks


 | Bookmark
Related Tutorials:
» Starting with XML
» Performing Client-Side XSL Transformations
» Create a Google Sitemap for your Web Site
» XML and Scripting Languages
» Parsing Comma-Separated Values
» XML Security Suite: Increasing the Security of E-Business