Entering content frame

Process documentation Multiple Output Documents

Purpose

The xsl:document element is used to create multiple result documents. As well as the main result document, subsidiary result documents may be available.

Process Flow

Each subsidiary result document is created using an xsl:document element. The content of the xsl:document element is a template; this is instantiated to create a sequence of nodes. A root node is created with this sequence of nodes as its children; the tree with this root node represents the subsidiary result document. The href attribute specifies where the subsidiary document should be stored; it must be an absolute or relative URI and must not have a fragment identifier.

For example the following XML file:

Example

<?xml version="1.0"?>
<grocery name = "The red tomato">
  <fruit>
    <article>Apples </article>
                <article>Pears </article>
                <article>Bananas</article>
  </fruit>
  <vegetables>
    <article>Cucumbers</article>
                <article>Tomatoes</article>
                <article>Peppers</article>
  </vegetables>
             </grocery>

will be processed with the following stylesheet:

Example

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="/">
    <main_output>
      Vegetables and Fruit
      <xsl:apply-templates/>
    </main_output>
  </xsl:template>
 
  <xsl:template match="grocery">
    <In_stock>
      <xsl:apply-templates/>
       <fruit>
        <xsl:value-of select = 'document("fruit\fruit.out")/fruit'>
        </xsl:value-of>
       </fruit>
       <vegetables>
        <xsl:value-of select = 'document("vegetables\vegetables.out")/vegetables'>
        </xsl:value-of>
       </vegetables>
       
    </In_stock>
  </xsl:template>

   <xsl:template match = "/grocery/fruit">
     <xsl:document href = "fruit\fruit.out">
       <fruit>
        <xsl:apply-templates/>
       </fruit>
     </xsl:document>
   </xsl:template>
  
<xsl:template match = "/grocery/vegetables">
     <xsl:document  href = "vegetables\vegetables.out">
       <vegetables>
         <xsl:apply-templates/>
       </vegetables>
     </xsl:document>
   </xsl:template>
  
</xsl:stylesheet>

Then two files will be created - \fruit\fruit.out and \vegetables\vegetables.out, containing the fruit and vegetables in stock, respectively. The combined information will be stored in the main output.

 

Leaving content frame