Re: One pass or two?

Subject: Re: One pass or two?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 25 Aug 1999 08:18:00 -0400
At 99/08/25 12:13 +0100, DPawson@xxxxxxxxxxx wrote:
given a DTD with

<!ELEMENT X (...)>
<!ATTLIST a             id      ID      #IMPLIED

Being lazy I haven't added the id's <oops/>


I can use generate-id(.) to obtain an id in an output element, but that appears on the output tree, hence I can't reference it on the input tree!

Actually, generate-id(.) gives a value for the current node of the source tree and you are adding it to the result tree. You can add the generated value for a given node any number of times to the result tree.


How to make use of an id value in the output tree?

generate-id() is used "blindly" ... the value is generated by the processor and can be used in the script but has no meaning that would make sense for pulling the value apart.


Do I need an identity transform to add the
ID's, then a transform to use the ID?

Since the value returned by this function for any given node is guaranteed to be the same within a single run of the processor, you need to refer to the node as many times as you need in the one result ... each time you access the same node in a given run, you will get the same value.


Using this function you can generate ID/IDREF pairs for/to nodes that do not already have a unique identifiers supplied by an ID attribute.

or can it be done in one pass?

A two-pass solution is never guaranteed to work when using generate-id(.) because the XSLT processor need only persist the generated id for a given source tree node through one run ... the values don't persist for "the next" run of the processor (it may be coincidental that they do, but that would only be coincidence).


Some implementations may base the generated value on document-order node presence, while others could base the generated value on a hexadecimal address of a storage structure in memory. How it is generated is up to the engine ... we just use it blindly.

I hope this helps.

........ Ken

--
G. Ken Holman                    mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999   (Fax:-0995)
Website:  XSL/XML/DSSSL/SGML services, training, libraries, products.
Practical Transformation Using XSLT and XPath      ISBN 1-894049-01-2
Next instructor-led training:                     MT'99 1999-12-05/06


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



Current Thread
  • One pass or two?
    • DPawson - Wed, 25 Aug 1999 12:13:53 +0100
      • G. Ken Holman - Wed, 25 Aug 1999 08:18:00 -0400 <=
      • <Possible follow-ups>
      • DPawson - Wed, 25 Aug 1999 16:32:29 +0100
      • DPawson - Thu, 26 Aug 1999 07:19:57 +0100