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

Tip: Create Multiple Files in XSLT 2.0

By Jack Herrington
2005-05-16


Use a single XSLT template to create multiple files

For any reasonably complex data set, you need multiple views to navigate it. Take a QA test system, for example: With a pool of tests and test results, you need to see the data by date, by test category, by individual test, and so on. Each view would be in its own HTML file. So, can you have a single template in XSLT 2.0 build multiple HTML files from the one input data set?

The first version of XSLT was very strict. It had one input and one output (although you could have more than one template file). Version 2 of the standard still restricts you to one input, but the output system is more flexible. Now, you can have multiple output files using the xsl:result-document directive. This new tag has two key attributes, as shown in Table 1.

Table 1. xsl:result-document attributes

AttributeDescription
hrefThe file name or fully qualified URL of the output file
formatThe name of the format to use as defined in a corresponding xsl:output directive

To test this directive, I have one input XML file that includes a set of test results (see Listing 1).

Listing 1. The input XML file


<?xml version="1.0" encoding="UTF-8"?>
<tests>
<testrun run="test1">
<test name="foo" pass="true" />
<test name="bar" pass="true" />
<test name="baz" pass="true" />
</testrun>
<testrun run="test2">
<test name="foo" pass="true" />
<test name="bar" pass="false" />
<test name="baz" pass="false" />
</testrun>
<testrun run="test3">
<test name="foo" pass="false" />
<test name="bar" pass="true" />
<test name="baz" pass="false" />
</testrun>
</tests>

This is pretty simple stuff. Within each test run is a set of named tests with the pass flag, which tells you whether the test was successful.



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