[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: copy single node once from one location to another

Subject: Re: copy single node once from one location to another
From: Peter Davis <pdavis152@xxxxxxxxx>
Date: Fri, 6 Sep 2002 15:43:49 -0700
xslt copy single node
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.