[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: generate-id()

Subject: Re: generate-id()
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 15 May 1999 13:15:28 -0400
xsl count child
At 99/05/11 15:55 +0100, Kay, Michael wrote:
>Has anyone found a use for generate-id()? (April 21 XSLT WD, section 6.2.2)
>It says it generates a string which "can be used as a unique identifier".
>Is this an identifier in the sense of the id() function? If so, does this
>mean the generated identifier is guaranteed distinct from any IDs actually
>present in the source document?
>If not, what is it for, and how can it be used?

I've used generate-id() already in two places, and there are probably many

(1) - identification of current location in an arbitrary node set (other
than the context node list):
- consider when the context node list isn't the list in which you wish to
find the current node
- the following code notes the generated id of the current node, then walks
through an arbitrary context node list generated by the for-each, doing
work only when at the (persistent (for the running of the script)) node

<xsl:template name="node-count">
  <xsl:variable name="this-id" expr="generate-id(.)"/>
  <xsl:for-each select="../node()|../@*"> <!--count child nodes &
    <xsl:if test="generate-id(.)=$this-id">
      <xsl:value-of select="position()"/>

(2) - tables of content:
- imagine you have a document with many sections and you want to create a
table of contents with each entry pointing to one of the sections
- the generate-id() function returns a value that parses as a name token
(e.g.: "N1", "N2", "N136", etc.), so I used it as it was given to me
- here are some snippets (I don't have the actual code I used at hand):

<xsl:template match="section">
  <a name="{generate-id(.)}"><xsl:value-of select="title"/>...

<xsl:template match="toc">
  <xsl:for-each select="//section">
    <a href="#{generate-id(.)}"><xsl:value-of select="title"/>...

I hope this helps.

........... Ken

G. Ken Holman                  mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.           http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0  +1(613)489-0999  (Fax:-0995)
Website: XSL/XML/DSSSL/SGML services outline,  XSL/DSSSL shareware,
         stylesheet resource library, conference training schedule,
         commercial stylesheet training materials, on-line XSL CBT.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.