RE: [xsl] Transforming a node in XSL multiple times

Subject: RE: [xsl] Transforming a node in XSL multiple times
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Tue, 29 Oct 2002 13:45:27 -0000
You need to think about this problem a different way. 

You could do your transformation in several passes, so that the result
of the first pass is the input to the second. You can do this either
with multiple stylesheets or by using temporary trees (result tree
fragments) and the xx:node-set() extension.

Or you can do it in a single pass, in which case each node in the result
tree must be computed as a function of the things in the source tree
that it depends on. You can visit a source node as often as you like,
but you can only visit a result node once.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Spencer
> Sent: 29 October 2002 07:21
> To: xsl list
> Subject: [xsl] Transforming a node in XSL multiple times
>  Hi!
>  We have a tag like this <img src="hello.bmp"/> and we want 
> to perform  multiple transformations on it such as adding alt 
> and width  attributes.  This can be done in one template quite easily.
> However, the problem arises if we need to change this tag 
> again but  through a different Xpath.  For example, we do a 
> template match on img  and add alt and width attributes.  
> Then we do a template match on the  div and because it has a 
> center alignment, we now want to add the  height attribute to 
> the preceeding image using the xpath  preceding::img
>  <img src="hello.bmp"/>
>  <div align="center"/>
>  This is a completely arbitary example, there are many 
> different cases  when we need to do similiar transformations 
> to the same tag but from  more than one template and/or a 
> different XPath that points to the  same tag.
>  In the template we use xsl:copy to output the tag and its changes. 
>  This prints the tag to the result tree, but we can no longer 
> change it  in a different template.  If we do (using another 
> xsl:copy) the img is  printed out again with different attributes.
>  How can we change this tag multiple times from multiple 
> templates but  have it only printed out once with all the 
> changes to it?
>  Thank you in advance for your help
>  XSL-List info and archive:

 XSL-List info and archive:

Current Thread