XSLT current() 函數

定義和用法
current() 函數返回僅包含當前節點的節點集。通常,當前節點與上下文節點是相同的。
<xsl:value-of select="current()"/>
等於
<xsl:value-of select="."/>
不過,有一點不同。讓我們看一下下麵的 XPath 運算式:"catalog/cd"。運算式選擇了當前節點的 <catalog> 子節點,然後選擇了 <catalog> 節點的 <cd> 子節點。這意味著,在計算的每一步上,"." 都有不同的意義。
下麵這行:
<xsl:apply-templates select="//cd[@title=current()/@ref]"/>
將處理 title 屬性的值等於當前節點的 ref 屬性的值的所有 cd 元素。
與這個不同:
<xsl:apply-templates select="//cd[@title=./@ref]"/>
這個會處理 title 屬性和 ref 屬性具有相同值的所有 cd 元素。
語法
node-set current()
實例 1
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="catalog/cd/artist">
Current node: <xsl:value-of select="current()"/>
<br />
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="catalog/cd/artist">
Current node: <xsl:value-of select="current()"/>
<br />
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
