다음을 통해 공유


document Function (Windows Embedded CE 6.0)

1/6/2010

Provides a way to retrieve other XML resources from within the XSL Transformations (XSLT) style sheet beyond the initial data provided by the input stream.

Syntax

            node-set document(object, node-set?)

Parameters

  • object
    String or node-set.
  • node-set
    [optional] Causes the function to return a base URL for the node.

Return Value

The document() function is versatile. Its effects vary, depending on the type and number of arguments that are used as shown in the following list:

  • If only one argument is provided and that argument is a string, then document() treats the string as a URL and retrieves the document as a set of nodes.
  • If only one argument is provided and that argument is a node set, then each node in that node set is treated as a URL and the function returns the union of all of the documents referenced.
  • If there are two arguments, the first argument can be either a string or a node set while the second argument must be a node set. The second argument, when supplied, indicates the base URL to which the contents of the first argument are relative.
  • If an empty string is passed to the document() function, the result is the source XML of the XSLT document itself, unless the second argument is given and is not null. In the latter case, the URL of the document is the base URL of the node contained in the second element.

Example

For the given XML document:

<employeeRefs>
   <employeeDoc href="http://www.example.microsoft.com/employees/employeeList.xml"/>
   <employeeDoc href="localEmployees1.xml"/>
   <employeeDoc href="localEmployees2.xml"/>
</employeeRefs>

The following style sheet generates a document containing the employee nodes in all of the referenced documents.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
    <employees>
        <xsl:apply-templates select="//employeeDoc"/>
    </employees>
</xsl:template>
<xsl:template match="employeeDoc">
    <xsl:copy-of select="document(@href)//employee"/>
</xsl:template>
</xsl:stylesheet>

See Also

Reference

XPath Node-Set Functions