Re: [xsl] [recursion pattern] sophisticated problem

Subject: Re: [xsl] [recursion pattern] sophisticated problem
From: Romeo.Disca@xxxxxxxxxxx (Romeo Disca)
Date: Wed, 17 Sep 2003 11:28:59 +0200
It's quite more complex. In the meantime I solved it with the recursion pattern.

The result document is a xsl stylesheet for use in an other transformation holding
the template document. Node X is a xsl:for-each node. While the others are
nodes of the template document. The idea is weaving data into the template.
Constraint: I don't know the structure of the template input tree. It could be any document.

My solution is this:
I test the first following sibling node of the current node.
Depending on that I decide to start the next level with the container node X.
In the next recursion levels I test if the current node is the last one that should
be contained in the container node X. Then i Terminate the recursion.
Significant is now that the rest of the list will not be processed.
So it was necessary to catch the processing at the rec level where I inserted
the X node and evaluated the rest of the nodes ( note: in this level there is a list containing
the nodes C and D, but we must get rid of them to get a proper result ) to start the recursion once again
with the rest. 

Figure: recursion stack


				D		F
			C		E
		X
	B
A
-----------------------------------------
					^- pass to rec [E,F]; pass not [C,D,E,F]

Romeo

Am Mittwoch, 17. September 2003 05:43 schrieb Michael Kay:
> You are trying to create one node in the output (X) corresponding to two
> nodes in the input (C and D). I classify all such problems as grouping
> problems, though this might be a rather simple one (but that depends on
> whether the range of possible inputs you need to deal with can be
> correctly inferred from your example).
>
> The basic approach is that you need to fire one template rule that
> processes the group as a whole. The solution might look like this:
>
> <xsl:template match="C">
> <X>
>   <xsl:copy-of select="."/>
>   <xsl:copy-of select="following-sibling::D[1]"/>
> </X>
> </xsl:template>
>
> <xsl:template match="D"/>
>
> Michael Kay
>
> > -----Original Message-----
> > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of
> > Romeo Disca
> > Sent: 16 September 2003 16:36
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject: [xsl] [recursion pattern] sophisticated problem
> >
> >
> > Hi,
> >
> > I'm trying to find a solution for copying an existing tree
> > with an identity transformation. Some nodes should be
> > modified. For the most tasks I have a solution but this one.
> >
> > Transforming a node like this:
> > ----------------
> > input tree:
> > /context-node/
> > 	+-/ A /
> > 	+-/ B /
> > 	+-/ C mode="x" /
> > 	+-/ D mode="x" /
> > 	+-/ E /
> > 	+-/ F /
> > -----------------
> > result tree:
> > /context-node/
> > 	+-/ A /
> > 	+-/ B /
> > 	+-/ X /
> > 		+-/ C mode="x" /
> > 		+-/ D mode="x" /
> > 	+-/ E /
> > 	+-/ F /
> > ===========
> >
> > My approach uses the recursion pattern (Kay 2001 p. 614) to
> > iterate through the child node list. The best I've got so far is:
> > -----------------
> > result tree:
> > /context-node/
> > 	+-/ A /
> > 	+-/ B /
> > 	+-/ X /
> > 		+-/ C mode="x" /
> > 		+-/ D mode="x" /
> > 		+-/ E /
> > 		+-/ F /
> > ===========
> >
> > I think this is so because the recursion levels lay upon each
> > other and inserting the X node in one effects the rest node
> > list even if I test for 'not mode' Nodes.
> >
> > Question: Is the recursion pattern the best way to do the job
> > and I only need to do more reasoning? Or, does anyone know an
> > alternative way to do that?
> >
> > Romeo
> >
> >
> > --
> > Romeo Disca
> > Email: romeo.disca@xxxxxxxxxxx
> >
> >  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

-- 
Romeo Disca
Email: romeo.disca@xxxxxxxxxxx

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread