XSLT generate-id() 函式
❮ XSLT 函式參考定義和用法
generate-id() 函式返回一個唯一標識指定節點的字串值。
如果指定的節點集為空,則返回空字串。如果省略節點集引數,則預設為當前節點。
語法
string generate-id(node-set?)
引數
引數 | 描述 |
---|---|
node-set | 可選。指定要生成唯一 ID 的節點集 |
示例 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>
<h3>藝術家:</h3>
<ul>
<xsl:for-each select="catalog/cd">
<li>
<a href="#{generate-id(artist)}">
<xsl:value-of select="artist" /></a>
</li>
</xsl:for-each>
</ul>
<hr />
<xsl:for-each select="catalog/cd">
藝術家: <a id="{generate-id(artist)}">
<xsl:value-of select="artist" /></a>
<br />
標題: <xsl:value-of select="title" />
<br />
價格: <xsl:value-of select="price" />
<hr />
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
❮ XSLT 函式參考