Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Recursive Traversal [Thread Next] Re: Recursive TraversalTo: NULL Date: 1/19/2005 9:50:00 PM Using XSLT 2.0 and FXSL the wanted result is effectively calculated with the following one-liner: f:zipWith(f:append(), f:scanl1(f:add(), data(/*/*/@X)), f:scanl1(f:add(), data(/*/*/@Y)) ) Here is the complete transformation: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:f="http://fxsl.sf.net/" exclude-result-prefixes="f" > <xsl:import href="../f/func-scanlDVC.xsl"/> <xsl:import href="../f/func-Operators.xsl"/> <xsl:import href="../f/func-append.xsl"/> <xsl:import href="../f/func-zipWith.xsl"/> <!-- To be applied on runningTotalsPairwise.xml --> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="/"> <xsl:sequence select= "f:zipWith(f:append(), f:scanl1(f:add(), data(/*/*/@X)), f:scanl1(f:add(), data(/*/*/@Y)) )"/> </xsl:template> </xsl:stylesheet> When applied on your source xml document : <DATA> <COORD X="10" Y="10"/> <COORD X="5" Y="-5"/> <COORD X="1" Y="1"/> </DATA> with Saxon 8.2 the wanted result is obtained: 10 10 15 5 16 6 Note also, that this transformation is much more efficient (must be linear) than the quadratic time-complexity solutions that are usually offered to this kind of problem. Cheers, Dimitre Novatchev. "Alfredo A. Ortega" <ortegaalfredo@g...> wrote in message news:e598931c.0501181155.345e38f@p...... > Hi all. > I'm having this trouble, seems simple but can't make it work: > > The data are relative 2D coordinates: > > <DATA> > <COORD X="10" Y="10"/> > <COORD X="5" Y="-5"/> > <COORD X="1" Y="1"/> > ... > </DATA> > > I need to calculate the intermediate sum of each one, so the output > for the data will look like: > > X=10 Y=10 > X=15 Y=5 > X=16 Y=6 > ... > > Now, the data files can have several megabytes, so this: > > <xsl:for-each select="COORD"> > <xsl:value-of > select="sum((.|preceding-sibling::COORD)/@X)"/>,<xsl:value-of > select="sum((.|preceding-sibling::COORD)/@Y)"/>, > </xsl:for-each> > > is way too slow. > > I'm experimenting with recursion with no luck, any help would be very > much appreciated ! > > Thanks all for your time - > Regards, Alfredo Ortega | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
