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 a repeatable unique id


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>
  </xsl:for-each>

(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:

  chapter[1]/section[2]/div[3]

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

  chapter1.section2.div3

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:

  id('PartII')/div[3]

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

Cheers,

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]