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 函数参考