current() and name() : current « XPath « XML Tutorial






File: Data.xml
<?xml version="1.0" encoding="utf-8"?>
<data>
    <item cell="1"> cell 1 </item>
    <item cell="2"> cell 2 </item>
    <name cell="1"> name 1 </name>
    <name cell="2"> name 2 </name>
    <size cell="1"> size 1 </size>
    <size cell="2"> size 2 </size>
</data>
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:template match="/data">
      <TABLE border="1">
        <xsl:apply-templates select="*[@cell='1']"/>
      </TABLE>
    </xsl:template>
    <xsl:template match="*">
      <TR>
        <TD>
          <xsl:value-of select="."/>
        </TD>
        <TD>
          <xsl:value-of select="//*[name()=name(current()) and @cell='2']"/>
        </TD>
      </TR>
    </xsl:template>
</xsl:stylesheet>

Output:

<?xml version="1.0" encoding="UTF-8"?><TABLE border="1"><TR><TD> cell 1 </TD><TD> cell 2 </TD></TR><TR><TD> name 1 </TD><TD> name 2 </TD></TR><TR><TD> size 1 </TD><TD> size 2 </TD></TR></TABLE>








4.3.current
4.3.1.current name
4.3.2.Sort by current value
4.3.3.current() returns a node-set that has the current node as its only member
4.3.4.get current node with current() function
4.3.5.current() and name()
4.3.6.Referring to the Current Node