|
Subject: Re: generate-id() From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Sat, 15 May 1999 13:15:28 -0400 |
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
more:
(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
identifier
<xsl:template name="node-count">
<xsl:variable name="this-id" expr="generate-id(.)"/>
<xsl:for-each select="../node()|../@*"> <!--count child nodes &
attributes-->
<xsl:if test="generate-id(.)=$this-id">
<xsl:value-of select="position()"/>
</xsl:if>
</xsl:for-each>
</xsl:template>
(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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| generate-id(), Kay Michael | Thread | XML parser, Bovone Stefano |
| Re: XLink implemented in XSL, James Clark | Date | Re: id/idref, G. Ken Holman |
| Month |