> XSLT中文手册 > XSLT key() 函数

XSLT key() 函数


完整的 XSLT 函数参考对象

定义和用法

key() 函数通过使用由 <xsl:key> 元素规定的索引号,从文档中返回节点集。


语法

node-set key(string, object)

参数

参数 描述
string 必需。规定 xsl:key 元素的名称。
object 必需。要搜索的字符串。

实例 1

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:key name="cdlist" match="cd" use="title" />

<xsl:template match="/">
<HTML>
<body>
<xsl:for-each select="key('cdlist', 'Empire Burlesque')">
<p>
Title: <xsl:value-of select="title" />
<br />
Artist: <xsl:value-of select="artist" />
<br />
Price: <xsl:value-of select="price" />
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

完整的 XSLT 函数参考对象