Re: [xsl] generating a repeatable unique id

Subject: Re: [xsl] generating a repeatable unique id
From: David_N_Bertoni@xxxxxxxxx
Date: Mon, 30 Jul 2001 15:06:17 -0700
Hi Michael,

generate-id() is not required to return the same value each time.  From the
recommendation:

   http://www.w3.org/TR/xslt#function-generate-id

   "An implementation is under no obligation to generate the same
   identifiers each time a document is transformed."

Xalan _does_ indeed return the same ID value every time.  That's because we
assign an integer to every node that gives the node's position in the
document -- an optimization for determining document order.  We use the
same value to generate the ID, so that's why you're seeing this behavior.

However, there is no guarantee that you will be able to depend upon this
behavior in future releases of the processor.  For instance, we might
decide that there is a more space-efficient way to optimize for document
order.  Or the parser might decide to generate attributes in a different
order, which would mean their IDs would change.

That said, we don't have any current plans to change things, so you can
probably get away with this for a while.

Dave



                                                                                                           
                    "Michael Beddow"                                                                       
                    <mbnospam@xxxxxxxxxxx>             To:     <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>           
                    Sent by:                           cc:     (bcc: David N Bertoni/CAM/Lotus)            
                    owner-xsl-list@xxxxxxxxxxxx        Subject:     Re: [xsl] generating a repeatable      
                    rytech.com                         unique id                                           
                                                                                                           
                                                                                                           
                    07/29/2001 03:01 AM                                                                    
                    Please respond to xsl-list                                                             
                                                                                                           
                                                                                                           



On Sunday July 29 2001 12:28 AM (or a little before, since my clock as I
reply says 11.00 BST)
Sebastian Rahtz wrote:

> All well and easy, if the <div> elements have ID attributes, but they
> don't. And generate-id() is not guarenteed to be the same on the next
> iteration (well, it isn't with libxslt, at least).

Ouch! Looks like I've got the wrong end of yet another stick. I know
that different XSLT processors aren't obliged (or even likely) to return
the same value for generate-id called on a given node, but is it in fact
permissible for the same processor to return a different generated id
for the same node on different runs? If so, I have a whole lot of
problems lurking that I'm not prepared for. So far, Xalan has always
behaved deterministically, returning the same value for identical nodes
in identical contexts over different runs. I was careless enough to
assume things were meant to be that way, and I've quite a bit of
important code that will break if that assumption ever proves false.

Michael
---------------------------------------------------------
Michael Beddow   http://www.mbeddow.net/
XML and the Humanities page:  http://xml.lexilog.org.uk/
---------------------------------------------------------



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list






 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread