XSLT key() 函式
❮ XSLT 函式參考定義和用法
key() 函式使用 <xsl:key> 元素指定的索引,從文件中返回一個節點集。
語法
node-set key(string, object)
引數
引數 | 描述 |
---|---|
string | 必需。指定 xsl:key 元素的名稱 |
object | 必需。一個要搜尋的字串 |
示例 1
<?xml version="1.0" encoding="UTF-8"?>
<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>
檢視 XML 檔案, 檢視 XSL 檔案, 以及 檢視結果。
❮ XSLT 函式參考