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

Reading external document using doc function

External document can be also read using doc() function. Function doc-available() tests for existence of a document on the specified address.
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">
                  <xxx>
                        <available-1>
                              <xsl:value-of  select="doc-available('ext3.xml')"/>
                        </available-1>
                        <available-2>
                              <xsl:value-of  select="doc-available('XYZ.xml')"/>
                        </available-2>
                        <xsl:copy-of  select="doc('ext3.xml')/rrr"/>
                  </xxx>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa/>

ext3.xml

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

      <xxx>
            <available-1>true</available-1>
            <available-2>false</available-2>
            <rrr>
                  <ccc  y="222"/>
            </rrr>
      </xxx>


Previous chapter: Groups
Next chapter: Multiple stylesheets
Previous page: Addressing in external documents
Next page: Reading external document with non-XML text