[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: One pass or two?
Sorry Ken, I'm not explaining very well: source document has an element <q> which I want to add to a table of contents. Being lazy, I haven't used the implied id Attribute in the DTD. Hence source line is: <q>blah</q> output wanted, in HTML The TOC which refers to the element via a hot link. <H4>Table of contents</H4> <p><a href="#N49">blah</a></p> ... Then in the body I need to have the id as the target of the link from the table of contents. <p> <a name="N49"> blah </a></p> The missing id attribute I can put in using generate-id() in the stylesheet, but I guess that the id isn't available for use on the input side? Hence I'm questioning if I need to do a two stage transform: a) transform from original source with an identity transform to which I simply add the id attribute to the source element of concern, e.g. ... <q>blah</q> to <q id="N49">blah</q> Then b)as part of the second transform.. create the toc and add a hotlink to the id created on the first run, using the output of the first transform as the input to the second one. The final output is html. Is that any better? regards, DaveP >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 > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|