O'Reilly logo

XSLT, 2nd Edition by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Example: Generating Multiple Output Files

The whole point of extensions is to allow you to add new capabilities to the XSLT processor. One of the most common needs is the ability to generate multiple output documents. As we saw earlier, the document() function allows you to have multiple input documents—but XSLT 1.0 doesn’t give us any way to create these. Saxon’s support for XSLT 2.0 includes the <xsl:result-document> element, which lets us generate multiple output documents. Although Xalan doesn’t support XSLT 2.0, it does support an extension element (<redirect:write>) that does the same thing. We’ll look at a stylesheet that uses <xsl:fallback> to generate useful results regardless of the processor we’re using. If we’re using Saxon or Xalan, we’ll get multiple output documents that are hyperlinked together; if we’re using any other processor, we’ll get a single HTML file that contains the same information.

Here’s the source document we’ll use:

<?xml version="1.0"?>
<!-- chapters.xml -->
<book>
  <title>XSLT Topics</title>
  <chapter>
    <title>XPath</title>
    <para>If this chapter had any text, it would appear here.</para>
  </chapter>
  <chapter>
    <title>Stylesheet Basics</title>
    <para>If this chapter had any text, it would appear here.</para>
  </chapter>
...
  <chapter>
    <title>Combining XML Documents</title>
    <para>If this chapter had any text, it would appear here.</para>
  </chapter>
</book>

In addition to the <xsl:fallback> element, our stylesheet also uses the element-available() function to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required