Tip: Create Multiple Files in XSLT 2.0
By Jack Herrington2005-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
| Attribute | Description |
href | The file name or fully qualified URL of the output file |
format | The 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 |
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
