当前位置: 首页 > 网络学院 > XML相关教程 > XSL/XSLT > XSLT current() 函数

XSL/XSLT
XSL 语言
XSLT 介绍
XSLT 浏览器
XSLT 转换
<xsl:template>
<xsl:value-of>
<xsl:for-each>
<xsl:sort>
<xsl:if>
<xsl:choose>
<xsl:apply-templates>
XSLT - 客户端
XSLT - 服务器端
XSLT - 编辑XML
XSLT 摘要
XSLT 元素参考
XSLT 函数
XSL 编辑器

XSL/XSLT 中的 XSLT current() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 208 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

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元素进行操作。


 

Syntax
语法

node-set current()

Example 1
案例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 文件以及结果

评论 (0) All

登陆 | 还没注册?