Latest web development tutorials

XSLT generate-id () function

XSLT Function Reference objects Complete XSLT Function Reference objects

Definition and Usage

generate-id () function returns a string that uniquely identifies the specified node value.

If the specified node-set is empty, an empty string is returned. If you omit the node-set argument, the default is the current node.


grammar

string generate-id(node-set?)

parameter

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

Example 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>

View the XML file , View the XSL file , view the results .


XSLT Function Reference objects Complete XSLT Function Reference objects