Latest web development tutorials

XSLT generate-id() 函數

XSLT 函數參考對象 完整的XSLT函數參考對象

定義和用法

generate-id() 函數返回唯一標識指定節點的字符串值。

如果指定的節點集是空的,則返回空字符串。 如果省略了node-set 參數,則默認設置為當前節點。


語法

string generate-id(node-set?)

參數

参数 描述
node-set 可选。规定要生成唯一 id 的节点集。

實例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>
<h3>Artists:</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">
Artist: <a name="{generate-id(artist)}">
<xsl:value-of select="artist" /></a>
<br />
Title: <xsl:value-of select="title" />
<br />
Price: <xsl:value-of select="price" />
<hr />
</xsl:for-each>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

查看XML文件查看XSL文件查看結果


XSLT 函數參考對象 完整的XSLT函數參考對象