Previous | Next | Indexes
Zvon > Tutorials > XSLT 2.0 Tutorial > Multiple Outputs (1/3) >

Output to multiple documents

Element xsl:result-document is used to output its contents to a file. Attribute href specifies a path to this file.

XSLT

      <xsl:stylesheet
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0">
            <xsl:output  method="xml"
                        indent="yes"
                        omit-xml-declaration="yes"/>
            <xsl:param  name="outdir">/path/to/outdir</xsl:param>

            <xsl:template  match="/aaa">
                  <xsl:apply-templates  select="*"/>
            </xsl:template>

            <xsl:template  match="*">
                  <xsl:result-document  href="{$outdir}/{name()}.xml">
                        <xsl:copy-of  select="."/>
                  </xsl:result-document>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa>
            <bbb/>
            <ccc/>
      </aaa>
Output
bbb.xml

      <bbb/>
ccc.xml

      <ccc/>


Previous chapter: Multiple stylesheets
Next chapter: Namespaces
Previous page: - - -
Next page: Output in different formats: xml, html, xhtml, and text