Previous | Next | Indexes
Zvon > Tutorials > XSLT 2.0 Tutorial > Multiple source documents (1/4) >

Reading external document with document() function.

External source documents can be read using document() function. This function is available in XSLT but not in other XPath usages (doc() function can be used outside XSLT usage and in this example both functions are equivalent).
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:template  match="/aaa">
                  <inner>
                        <xsl:copy-of  select="."/>
                  </inner>
                  <external>
                        <xsl:copy-of  select="document('ext1.xml')"/>
                  </external>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa>
            <bbb  x="111"/>
      </aaa>

ext1.xml

      <rrr>
            <ccc  y="222"/>
      </rrr>
Output

      <inner>
            <aaa>
                  <bbb  x="111"/>
            </aaa>
      </inner>
      <external>
            <rrr>
                  <ccc  y="222"/>
            </rrr>
      </external>


Previous chapter: Groups
Next chapter: Multiple stylesheets
Previous page: - - -
Next page: Addressing in external documents