select by id() : id « XSLT stylesheet « XML Tutorial






File: Data.xml
<?xml version="1.0" encoding="UTF-8"?>
<provinces>
 <province id="AB">
  <name>Alberta</name>
  <abbreviation>AB</abbreviation>
 </province>
 <province id="BC">
  <name>British Columbia</name>
  <abbreviation>BC</abbreviation>
 </province>
 <province id="MB">
  <name>Manitoba</name>
  <abbreviation>MB</abbreviation>
 </province>
 <province id="NB">
  <name>New Brunswick</name>
  <abbreviation>NB</abbreviation>
 </province>
</provinces>


File: Transform.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="text" />

  <xsl:template match="provinces">
    <xsl:apply-templates select="id('NU')" />
  </xsl:template>

  <xsl:template match="id('NU')">
    <xsl:value-of select="name" />
  </xsl:template>

</xsl:stylesheet>








5.55.id
5.55.1.id() takes a string as its argument and returns a node-set containing any node that has an attribute of type ID equal to the function's argument
5.55.2.Compare id
5.55.3.select by id()
5.55.4.Here is a test of the id()
5.55.5.The id function selects elements by their unique ID.