Re: Generating IDs for each element

Subject: Re: Generating IDs for each element
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 04 Sep 2000 20:25:46 +0100
Mal,

>I want to be able to generate a unique ID for each element that I will then
>be able to access in another parse invocation.

How to do this really depends on whether and in what way your source
document is going to change across invocations.  A simple approach is to
generate an id that uniquely identifies the element within the document by
numbering all the elements of a certain type:

  <xsl:value-of select="name()">-<xsl:number level="any" />

will generate para-1, para-2, para-3 and so on throughout the document.
The xsl:number with level="any" numbers instances of the element across the
entire document.  This is enough if your source document is not going to
change at all across invocations.

Otherwise you need something a bit more complex, and that relies on asking
the question: what is it that uniquely identifies this element?  It could
be its content, the combination of values of attributes, its position, or
anything.  Once you've answered that question, you can use the answer to
generate the unique id. 

I hope that this helps,

Jeni

Jeni Tennison
http://www.jenitennison.com/


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


Current Thread