Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

id Function

Selects elements by their unique ID.

          node-set id(object)

When the argument is of type node-set, the result is the union of the result of applying id() to the string value of each of the nodes in the node-set argument.

When the argument is of any other type, it is converted to a string and then split into a white space–separated list of tokens (white space is any sequence of characters matching the production); the result is a node-set containing the elements in the same document as the context node that have a unique ID equal to any of the tokens in the list.

XML FILE (test.xml)

<?xml version="1.0"?>
<!DOCTYPE test [
  <!ELEMENT test (x+)>
  <!ELEMENT x (x+| y+)>
     a ID #REQUIRED>
    <x a="a11">
      <x a="a21">
        <x a="a31">
    <x a="a12">
      <x a="a22">
    <x a="a13">
    <x a="a14">

XSLT File (test.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"

  <xsl:output method="xml" omit-xml-declaration="yes"/>

  <!-- suppress text nodes not covered in subsequent        template rule -->
  <xsl:template match="text()"/>

  <xsl:template match="*">
    <xsl:element name="{name()}">
      <xsl:apply-templates select="*|@*"/>
      <xsl:if test="text()">
         <xsl:value-of select="."/>

  <xsl:template match="@*">
    <xsl:attribute name="{name()}">
      <xsl:value-of select="."/>

  <xsl:template match="/test">
    <xsl:apply-templates select="id('a21') "/>
    <xsl:apply-templates select="id('a11')//y[1]"/>



The XSLT stylesheet, when applied to the XML file above results in the following node-set:

<x a="a21">

<x a="a31">







Build Date:

© 2015 Microsoft