当前位置: 首页 > 网络学院 > XML相关教程 > XSL/XSLT > XSLT current() 函数
The current() function returns a node-set that contains only the current node. Usually the current node and the context node are the same.
current() 函数的作用是:返回一个仅包含当前节点的节点组。current [当前]节点和context[内容]节点相同,即:<xsl:value-of select="current()"/>等于<xsl:value-of select="."/>。
However, there is one difference. Look at the following XPath expression: "catalog/cd". This expression selects the <catalog> child nodes of the current node, and then it selects the <cd> child nodes of the <catalog> nodes. This means that on each step of evaluation, the "." has a different meaning.
然而,它们之间也存在着差异。请看下面的XPath表达式:"catalog/cd"。该表达式选择了当前节点中的<catalog>子节点,然后它又选择了<catalog>子节点中的 <cd>子节点,这意味着每一个操作步骤中所用到的 "." 含义都不相同。
The following line:
<xsl:apply-templates select="//cd[@title=current()/@ref]"/>
will process all cd elements that have a title attribute with value equal to the value of the current node's ref attribute.
This is different from
<xsl:apply-templates select="//cd[@title=./@ref]"/>
that will process all cd elements that have a title attribute and a ref attribute with the same value.
下面这行表达式<xsl:apply-templates select="//cd[@title=current()/@ref]"/>将对所有的CD元素值进行操作,该CD元素中的title属性值与当前节点的ref属性值相同;上述表达式不同于下面这个表达式:<xsl:apply-templates select="//cd[@title=./@ref]"/>,它将对所有的包含相同title属性值和ref属性值的CD元素进行操作。
node-set current() |
<?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> |