Latest web development tutorials

XSLT current() 函數

XSLT 函數參考對象 完整的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]"/>

將處理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>

查看XML文件查看XSL文件查看結果


XSLT 函數參考對象 完整的XSLT函數參考對象