Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Recursive Traversal

From: "Dimitre Novatchev" <dnovatchev@-----.--->
To: 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 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent