generate-id Function

Returns a string that uniquely identifies the node in the node-set argument that is first in document order.

          string generate-id(node-set?)

The unique identifier must consist of ASCII alphanumeric characters and must start with an alphabetic character. Thus, the string is syntactically an XML name. There is no guarantee that a generated unique identifier will be distinct from any unique IDs specified in the source document. If the node-set argument is empty, the empty string is returned. If the argument is omitted, it defaults to the context node.

XML File (data.xml)

<?xml-stylesheet type="text/xsl" href="sample.xsl"?>
    <book id="bk101">
        <author>Gambardella, Matthew</author>
        <title>XML Developer's Guide</title>
        <description>An in-depth look at creating applications with XML.</description>
    <book id="bk102">
        <author>Ralls, Kim</author>
        <title>Midnight Rain</title>
        <description>A former architect battles corporate zombies.</description>

XSLT File (sample.xsl)

<xsl:stylesheet xmlns:xsl="" version="1.0">
    <xsl:output method="html"/>
  <xsl:template match="/">
                <xsl:for-each select="//book">
                    <button id="{generate-id(author)}" onclick="alert(">
                        <xsl:value-of select="author"/>

This is the formatted output:

Formatted output for generate_id function

When you click the left button in Internet Explorer, an alert box displays "IDAHAGJD".

When you click the right button in Internet Explorer, an alert box displays "IDAPAGJD".

Notice that the ID value is generate at run-time. Therefore, the specific values may vary in different invocation of the transformation.

This is the processor output:


<body><button id="IDAHAGJD" onclick="alert(">Gambardella, Matthew</button>

<button id="IDAPAGJD" onclick="alert(">Ralls, Kim</button></body>


Build Date: