Re: [xsl] generating a repeatable unique id

Subject: Re: [xsl] generating a repeatable unique id
From: Colin Muller <colin@xxxxxxxxxxxxxx>
Date: Sun, 29 Jul 2001 19:14:20 +0800
On Sun, Jul 29, 2001 at 12:28:45AM +0100, Sebastian Rahtz wrote:
> Consider this skeleton document:
> <root>
> <front>
> <div/><div/><div/>
> </front>
> <body>
> <div/><div/><div/>
> </body>
> </root>
> I want to generate a repeatable ID for any <div> on the fly. 

> make myself a key table, which lets me identify a target <div> quickly
> when the key value is passed in:
>  <xsl:key name="DIVS" 
>    match="div" 
>    use="concat(name(..),concat('_',concat(name(.),concat('_',count(preceding-sibling::div)))))"/>
> This works, but the procesing cost looks to be silly, doing that
> count of preceding-siblings for every div.

Not sure how repeatable 'repeatable' needs to be, but if the document
is not going to change before you get back to it with the id, you can
do what I do when creating HTML forms for editing XML docs: save a
temporary file in which every element gets associated with this:

<xsl:attribute name="">
    <xsl:number level="any" count="*"/>

(angazi in there is a Zulu sentence meaning "I don't know", and is the
name of an agnostic content manager I wrote and use)

... and name the HTML form input elements accordingly:
input name="whatever_the_relevant_count_value_is". On the way back
in, I just need to have kept track of the xpath-count_number
association to be able tp put things back in the right place.

This has never created an unacceptable (for my purposes) processor
overhead, so I've never questioned how the processors actually handle
the count, but I've presumed that there's some sort of an internal
stack on which it's uncostly to count the total number of elements up
to and including a certain one - if indeed that count is not in any
case already known for the processor's own nefarious internal
purposes. You have no need to keep track of anything other than the
total count, of course: the numbers you actually use don't need to be


 XSL-List info and archive:

Current Thread