The document (URL) function parses an external XML document (not an XML source document for conversion) into an XML node tree that can be directly referenced. The URL parameter specifies the physical address of the external XML document.
Syntax: document (URL)
Parameter: URL string, required
Return Value: Node Set
Example:
Document. xml:
<?xml version="1.0" encoding="UTF-8"?><color>blue</color>
Xml source document:
<?xml version="1.0" encoding="UTF-8"?><colors> <color>red</color> <color>green</color> <color>blue</color></colors>
Xslt:
<? Xml version = "1.0" encoding = "UTF-8"?> <Xsl: stylesheet version = "1.0" xmlns: xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl: output method = "html" version = "1.0" encoding = "gb2312" indent = "yes"/> <xsl: template match = "/colors"> <xsl: for-each select = "color"> <xsl: if test = "document ('document. xml ')/color =. "> <xsl: value-of select = ". "/> <xsl: text> is located at </xsl: text> <xsl: value-of select =" position () "/> </xsl: if> </xsl: for-each> </xsl: template> </xsl: stylesheet>
Result:
Blue is at 3.