This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Generating IDs for each element


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]