Re: [xsl] Recursive substitution

Subject: Re: [xsl] Recursive substitution
From: Agnisys <agnisys@xxxxxxxxx>
Date: Thu, 3 Nov 2005 14:21:16 -0800 (PST)
To illustrate what I mean by "stiching" please see the example below. When node DEF2 is
referenced, the new tree is processed as if the node existed there. So all the axis are modified
accordingly. Thats the reason I had to use "copy-of".

Input XML:
<x>
   <define name="DEF1">
        <reg name="REG1"/>
    </define>
    
    <define name="DEF2">
        <reg name="REG2"/>
        <ref name="DEF1"/>
    </define>
     
     <block name="block1">
         <reg name="REG4"/>
         <reg name="REG3"/>
         <ref name="DEF2"/>
     </block>
</x>

Output:
Register: REG4 Prev-sibling: 
Register: REG3 Prev-sibling: REG4
Register: REG2 Prev-sibling: REG3
Register: REG1 Prev-sibling: REG2

Thanks for your help.
Anupam.

--- David Carlisle <davidc@xxxxxxxxx> wrote:

> 
> > Unfortunately my problem is that I did want to use a "copy-of" so that the nodes being
> referred to
> > by the <ref> tag are actually "stitched" into the tree.
> 
> I have no idea what you mean by stiched here. The code I posed roduced
> the output you saod you needed, if in fact you need different output I
> suggest that you repost with a different sample result.
> 
> I applied templates to the refereneced nodes.
> 
> > <xsl:template match="ref">
> >  <xsl:apply-templates select="key('r',@name)"/>
> > </xsl:template>
> 
> 
> You generate a new tree in memory that consist just of a document node
> with child the referenced nodes, and then apply templates to that.
> 
>     <xsl:template match="ref[@name]"> 
>         <xsl:variable name="x">
>             <xsl:copy-of select="key('r',@name)"/>
>         </xsl:variable>
>         <xsl:apply-templates select="$x"/>
>     </xsl:template>
> 
> This takes mre memory, because of the copy but will produce the smae
> result unless your have a template matching / that does something other
> han the default action of applying templates to your children, or if the
> templates that match the referenced nodes use Xpath expressions to
> select their parsents or any other ancestor, as in my version they will
> have the parents they had in the original tree, but in your version the
> tree only has these nodes,all with parent /
> 
> David
> 
> ________________________________________________________________________
> This e-mail has been scanned for all viruses by Star. The
> service is powered by MessageLabs. For more information on a proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk
> ________________________________________________________________________
> 
> 



		
__________________________________ 
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com

Current Thread