XSLT current() 函式
❮ XSLT 函式參考定義和用法
current() 函式返回一個只包含當前節點的節點集。通常,當前節點和上下文節點是相同的。
<xsl:value-of select="current()"/>
等同於
<xsl:value-of select="."/>
然而,有一個區別。請看下面的 XPath 表示式:“catalog/cd”。這個表示式選擇當前節點的 <catalog> 子節點,然後選擇 <catalog> 節點的 <cd> 子節點。這意味著在每次求值步驟中,“.” 具有不同的含義。
以下行
<xsl:apply-templates select="//cd[@title=current()/@ref]"/>
將處理所有 `cd` 元素,這些元素的 `title` 屬性值等於當前節點的 `ref` 屬性值。
這與
<xsl:apply-templates select="//cd[@title=./@ref]"/>
不同,後者將處理所有具有 `title` 屬性且該屬性值與 `ref` 屬性值相同的 `cd` 元素。
語法
node-set current()
示例 1
<?xml version="1.0" encoding="UTF-8"?>
<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">
當前節點:<xsl:value-of select="current()"/>
<br />
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
❮ XSLT 函式參考