On Friday 06 September 2002 14:46, Thomas Olausson wrote:
I'd like to write a XSLT that moves the data_text to the corresponding
index of "a", expressed in data_nr. In the above case, /mydoc/a[2]
The way you are thinking about this is completely inverse of how XSLT works.
You can't "move" a <data_text> into /mydoc/a[2], but you *can* output the
second <a> and output the correct <data_text> as a child at the same time.
Does that make any sense? You have to select the correct <data_text> element
at the time that you copy it; you can't have a template for <data_text> that
says "Oh, I should have copied this into the <a> that I already copied."
That means you have to put this code into the template that copies the <a>.
Once you realize that, it's pretty easy to realize how to determine the index
of the current <a>, and look up the correct <data_text> with something like
"/mydoc/specials[data_nr=$index]/data_text". Once you have that in your
head, the next logical step is to use <xsl:key> to do the lookup qickly and
more simply.
I hope that clarifies how I arrived at my solution. In general, working with
XSLT is often backwards from the way you work with other procedural
programming languages. Some day, you will have an epiphany, and everything
will become easier.
--
Peter Davis
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list