This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Generating IDs for each element
- To: Malcolm Locke <malcolm dot locke at net800 dot co dot uk>
- Subject: Re: Generating IDs for each element
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Mon, 04 Sep 2000 20:25:46 +0100
- Cc: xsl-list at mulberrytech dot com
- Reply-To: xsl-list at mulberrytech dot com
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