Re: [xsl] generating a repeatable unique id

Subject: Re: [xsl] generating a repeatable unique id
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 30 Jul 2001 10:03:00 +0100
Hi Sebastian,

> Hmm, interesting idea. My real problem with that is that I am inside
> a web server at transformation time, and I dont really want it
> scribbling temporary files. Apart from anything else, it *could* be
> weeks before someone hits the link button which activates the
> request for a section. Of course, this screws me anyway, as the
> original document might have changed... oh yuck.

Since you're dealing with documents that might change, perhaps you
could generate links that look like XPaths. These would be more stable
than a count of all preceding elements of the same name. For example:

  <xsl:for-each select="ancestor-or-self::*">
    <xsl:value-of select="name()" />
    <xsl:text />[<xsl:number />]<xsl:text />
    <xsl:if test="position() != last()">/</xsl:if>

(or, more efficiently, pass down path as you journey down the tree
rather than creating it from scratch for each element.)

This would create things like:


Of course you should use different separators to make it a valid ID so
that it can be an HTML anchor, e.g.:


Another idea would be to only use these kind of paths from the nearest
available element with an ID attribute. So if section[2] actually has
an ID of "PartII" then you could have:


or (again) something similar that could be a valid ID. This would make
the IDs more stable over time.



Jeni Tennison

 XSL-List info and archive:

Current Thread