Subject: RE: [xsl] Unbounded element grouping/concatenation From: "Gupta, Raman K [CI]" <raman.k.gupta@xxxxxxxxxxxxx> Date: Tue, 9 Dec 2003 11:24:10 -0500 |
> I am trying to do something similar to the XSLT FAQ on Grouping, > question 17. Concatenate two elements. Here is the original question > for your reference: > > > <record n="1" type="normal"> > > <foo> <x>... <y>...</y> ...</x> </foo> > > <bar> <things> ... </things> </bar> > > </record> > > <record n="2" type="normal"> > > <foo> <x>... <y>...</y> ...</x> </foo> > > </record> > > <record n="3" type="continuation"> > > <bar> <things> ... </things> </bar> > > </record> > > <record n="4" type="normal"> > > <foo> <x>... <y>...</y> ...</x> </foo> > > <bar> <things> ... </things> </bar> > > </record> > > [...] > > Now, in my case I do have an unbounded number of continuation records for > each normal record, and I need to concatenate all of them. > > I followed Jeni's advice, and created a key as follows (this is my > understanding of her directions, I could be wrong): > > [...] > The following template (based on the flat file section of the FAQ), works much faster, presumably because it only iterates over all of the continuation records once for each normal record, instead of once for each continuation record: <xsl:template match="records"> <xsl:apply-templates select="record[@type = 'normal']" /> </xsl:template> <xsl:template match="record"> <record> <xsl:copy-of select="*" /> <xsl:apply-templates select="following-sibling::record[@type = 'continuation' and generate-id(preceding-sibling::record[@type = 'normal']) = generate-id(current())]" mode="continue"/> </record> </xsl:template> <xsl:template match="record" mode="continue"> <xsl:copy-of select="*" /> </xsl:template> However, I still think there are even better ways of doing this, because in the above template there is still a lot of wasted iteration. Recursion works quickly without wasting iteration, but tail recursion optimization doesn't seem to be supported by Xalan-J 2.4.0, because I get stack overflows for large numbers of continuation records. Perhaps the DVC approach that I've read a little about would help here? Cheers, Raman Gupta XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Unbounded element grouping/co, Gupta, Raman K [CI] | Thread | [xsl] Re: Unbounded element groupin, Dimitre Novatchev |
SOLUTION:RE: [xsl] Re: Re: Re: How , Ficke, Bill | Date | Re: [xsl] Missing nodes are ruining, David Carlisle |
Month |