Altova Mailing List Archives

RE: One pass or two?

From: "G. Ken Holman" <gkholman@-------------------->
Date: 8/25/1999 9:09:00 AM
At 99/08/25 16:32 +0100, DPawson@xxxxxxxxxxx wrote:

Sorry Ken, I'm not explaining very

Sorry, Dave, I must not be answering very well.  :{)}

source document has an element <q>

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:


output wanted, in HTML

The TOC which refers to the element via a hot link.

        <H4>Table of


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?

... but it is available from the input at all times during the run.

For what you need, you need only go over the source tree twice, once for
the table of contents and once for the body (or, of course, any other
times you may wish to visit the source tree).

Each time around you use generate-id(.) in a different construct of the
result tree, but because it is one run of the XSLT engine the value
returned for a given node is guaranteed to be the same.  As soon as
you finish the run that guarantee is gone ... the next time around you
must treat the value created by generate-id(.) as brand new, even if it
coincidentally happens to be what it was before.

Note that the value generated for the result tree comes from the node in
the source tree ... you aren't asking anything about the result

I hope the example below helps.

........... Ken

T:\dave>type test.xml

<?xml version="1.0"?>


  <q>blah 1</q>

  <q>blah 2</q>


T:\dave>type test.xsl

<?xml version="1.0"?>


<xsl:output indent="yes"/>

<!--root rule-->


  <xsl:for-each select="//q">







<xsl:template match="q">




T:\dave>call xsl test.xml test.xsl test.htm

T:\dave>type test.htm



<a href="" 1</a>



<a href="" 2</a>




<a name="N3">blah 1</a>



<a name="N6">blah 2</a>




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


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.