RE: [xsl] Calculating cumulative values

Subject: RE: [xsl] Calculating cumulative values
From: "Simon Shutter" <simon@xxxxxxxxxxx>
Date: Sun, 4 Feb 2007 15:56:38 -0800
Thank you for the very helpful explanation Dimitre. 

-----Original Message-----
From: Dimitre Novatchev [mailto:dnovatchev@xxxxxxxxx] 
Sent: February 4, 2007 3:41 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Calculating cumulative values

On 2/4/07, Simon Shutter <simon@xxxxxxxxxxx> wrote:
> Does this dependence on the implementations of the processor mean that
> xxx:node-set() is limited to server-side processing or client-side 
> where the environment is guaranteed?

If by client-side you mean inside IE, then you have to use the
msxsl:node-set() extension function (where msxsl is bound to the
namespace: "urn:schemas-microsoft-com:xslt"), because IE uses internally
MSXML (3) and at this date none of the MSXML engines implements EXSLT.

It was announced recently that Firefox 3 will implement a subset of EXSLT,
including the node-set() extension.

In case you are using MSXML4, you could use also my implementation of a
subset of EXSLT (described at:
http://www.xml.com/pub/a/2003/08/06/exslt.html)

For the .NET XSLT processors there is a full EXSLT implementation produced
by Dare Obasanjo, Oleg Tkachenko and partly (the Sets
functions) by me. It can be found at Oleg's site (tkachenko.com).

As one can see, the main idea of EXSLT was to provide a portable set of
extensions, however the degree of completeness of their implementation and
the availability using different XSLT processors makes using EXSLT not that
straightforward...

Compare with a library of functions written entirely in XSLT, thus by
definition available on any compliant XSLT processor (really, I am speaking
about XSLT 2.0 here!) and easily extensible (and thus much more powerful) by
anyone, without the need for permissions, agreements and long debates.


>
> Also, I read on http://www.tkachenko.com/blog/archives/000559.html 
> that msxsl and exsl are equivalent - if so, should I then use exsl in 
> the .net 2.0 environment?

Oleg does not sy this, he says that exsl:node-set() is implemented. I cannot
comment on this, however it is often recommended not to depend on
undocumented features.


--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play



>
> [Note to self  :  RTF = result tree fragment - hey, I'm on a very steep
> curve here!]
>
> -----Original Message-----
> From: Simon Shutter [mailto:simon@xxxxxxxxxxx]
> Sent: February 4, 2007 12:11 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Calculating cumulative values
>
> Thanks, Dimitre - I'll try that
>
> -----Original Message-----
> From: Dimitre Novatchev [mailto:dnovatchev@xxxxxxxxx]
> Sent: February 4, 2007 7:20 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] Calculating cumulative values
>
> > If I needed to sort the data before I determined the cumulative
> > numbers, how do I ensure this happens before aggregating the data?
>
> This is a well-known technique, which requires the use of (in your case
> msxsl:node-set() ) the extension function exsl:node-set() or the
> XSLT-processor-implemented xxx:node-set() extension function.
>
> A smal blueprint is below:
>
>  <xsl:variable name="vrtfOtputTree">
>      <!-- Whatever processing required to produce a new tree -->
>  </xsl:variable>
>
>  <xsl:variable name="vOutputTree" select="xxx:node-set($vrtfOtputTree)"/>
>
> <!-- Then continue with using the temporary tree that was obtained from
the
> RTF -->
>
>   <!-- For example: -->
>
>   <xsl:value-of select="$vOutputTree/*/*[1]"/>
>
> Of course, one can use FXSL for XSLT 1.0 and use the same approach, shown
in
> the FXSL 2.0 solution.
>
>
> --
> Cheers,
> Dimitre Novatchev
> ---------------------------------------
> Truly great madness cannot be achieved without significant intelligence.
> ---------------------------------------
> To invent, you need a good imagination and a pile of junk
> -------------------------------------
> You've achieved success in your field when you don't know whether what
> you're doing is work or play
>
>
>
> On 2/3/07, Simon Shutter <simon@xxxxxxxxxxx> wrote:
> > I think I may go with 'conventional' solution provided by Andrew,
> > because
> it
> > is natively supported by .Net 2 and my data sets are relatively small
> > and tranformed pretty quickly.  I will look more into FXSL for the
> > longer
> term.
> >
> > If I needed to sort the data before I determined the cumulative
> > numbers,
> how
> > do I ensure this happens before aggregating the data?
> >
> > Thanks,
> >
> > Simon
> >
> >
> > -----Original Message-----
> > From: Dimitre Novatchev [mailto:dnovatchev@xxxxxxxxx]
> > Sent: February 3, 2007 4:48 PM
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject: Re: [xsl] Calculating cumulative values
> >
> > On 2/3/07, Simon Shutter <simon@xxxxxxxxxxx> wrote:
> > > Thanks, Dimitre.
> > >
> > > Two questions -
> > >
> > > a) Will this work with .Net 2.0?
> >
> > No, the two XSLT processors that come as part of  .NET 2.0 (the
> > classes XslTransform and XslCompiledTransform) only support XSLT 1.0.
> >
> > However, in a .NET environment one can use Saxon.NET, which is a port
> > of Saxon 8.x and implements XSLT 2.0.
> >
> >
> > >
> > > b) What are the external files : func-scanlDVC.xsl and
> func-Operators.xsl?
> >
> > They are part of the FXSL library.
> >
> > The latest version of FXSL can be checked out from the CVS of the
> > project
> > at:
> >
> >   http://sourceforge.net/cvs/?group_id=53841
> >
> >
> > One can learn more about FXSL from the presentations made at the
> > Extreme Markup Languages Conference in Montreal 2006 (FXSL 2 -- for
> > XSLT 2.0, and FXSL 1 -- for XSLT 1.0) here:
> >
> >
> >
>
http://www.idealliance.org/papers/extreme/proceedings/xslfo-pdf/2006/Novatch
> > ev01/EML2006Novatchev01.pdf
> >
> > and here:
> >
> >
> >
>
http://www.idealliance.org/papers/extreme/proceedings/xslfo-pdf/2003/Novatch
> > ev01/EML2003Novatchev01.pdf
> >
> >
> > Other papers about different important features of FXSL can be found
> > at
> the
> > home page of FXSL:
> >
> >   http://fxsl.sf.net
> >
> >
> >
> > --
> > Cheers,
> > Dimitre Novatchev
> > ---------------------------------------
> > Truly great madness cannot be achieved without significant intelligence.
> > ---------------------------------------
> > To invent, you need a good imagination and a pile of junk
> > -------------------------------------
> > You've achieved success in your field when you don't know whether what
> > you're doing is work or play
> >
> >
> >
> >
> >
> > >
> > > Simon
> > >
> > > -----Original Message-----
> > > From: Dimitre Novatchev [mailto:dnovatchev@xxxxxxxxx]
> > > Sent: February 3, 2007 2:50 PM
> > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > > Subject: Re: [xsl] Calculating cumulative values
> > >
> > > On 2/3/07, Andrew Welch <andrew.j.welch@xxxxxxxxx> wrote:
> > >
> > > >
> > > > You can just use XPath here, no need for recursion:
> > > >
> > > > <xsl:template match="point">
> > > >  <xsl:copy>
> > > >   <xsl:copy-of select="@*"/>
> > > >   <xsl:attribute name="y2">
> > > >     <xsl:value-of select="sum(./@y1|preceding-sibling::point[@x =
> > > > current()/@x]/@y1)"/>
> > > >   </xsl:attribute>
> > > >  </xsl:copy>
> > > > </xsl:template>
> > >
> > >
> > > However evaluating this XPath expression repeatedly is O(N^2) and
> > > will probably be slow for long lists.
> > >
> > > Here is a solution, using the FXSL function
> > >
> > >      f:scanl1()
> > >
> > > This 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"/>
> > >
> > >  <!-- To be applied on testFunc-scanlDVC3.xml -->  <xsl:output
> > > omit-xml-declaration="yes" indent="yes"/>
> > >
> > >
> > >  <xsl:template match="node()|@*">
> > >    <xsl:copy>
> > >      <xsl:apply-templates select="node()|@*"/>
> > >    </xsl:copy>
> > >  </xsl:template>
> > >
> > >  <xsl:template match="set">
> > >    <xsl:copy>
> > >      <xsl:copy-of select="@*"/>
> > >      <xsl:for-each-group select="point" group-by="@x">
> > >         <xsl:for-each select="f:scanl1(f:add(), current-group()/@y1)">
> > >            <point x="{current-group()[1]/@x}" y="{.}"/>
> > >         </xsl:for-each>
> > >     </xsl:for-each-group>
> > >    </xsl:copy>
> > >  </xsl:template>
> > > </xsl:stylesheet>
> > >
> > > When applied against the originally provided xml document:
> > >
> > > <root id="theroot">
> > >        <set id="1">
> > >                <point x="1" y1="2" />
> > >                <point x="1" y1="3" />
> > >                <point x="1" y1="0" />
> > >                <point x="1" y1="2" />
> > >                <point x="1" y1="2" />
> > >                <point x="2" y1="3" />
> > >                <point x="2" y1="0" />
> > >                <point x="2" y1="2" />
> > >                <point x="3" y1="2" />
> > >                <point x="3" y1="3" />
> > >                <point x="3" y1="1" />
> > >                <point x="3" y1="2" />
> > >                <point x="3" y1="2" />
> > >        </set>
> > >        <set id="2">
> > >                <point x="1" y1="2" />
> > >                <point x="1" y1="3" />
> > >                <point x="1" y1="0" />
> > >                <point x="1" y1="2" />
> > >                <point x="2" y1="2" />
> > >                <point x="3" y1="2" />
> > >                <point x="3" y1="2" />
> > >                <point x="3" y1="2" />
> > >        </set>
> > >        <set id="n">
> > >                <point x="1" y1="2" />
> > >                <point x="1" y1="3" />
> > >                <point x="1" y1="2" />
> > >                <point x="2" y1="3" />
> > >                <point x="2" y1="0" />
> > >                <point x="2" y1="2" />
> > >                <point x="3" y1="3" />
> > >        </set>
> > > </root>
> > >
> > > produces the wanted result:
> > >
> > > <root id="theroot">
> > >   <set id="1">
> > >      <point x="1" y="2"/>
> > >      <point x="1" y="5"/>
> > >      <point x="1" y="5"/>
> > >      <point x="1" y="7"/>
> > >      <point x="1" y="9"/>
> > >      <point x="2" y="3"/>
> > >      <point x="2" y="3"/>
> > >      <point x="2" y="5"/>
> > >      <point x="3" y="2"/>
> > >      <point x="3" y="5"/>
> > >      <point x="3" y="6"/>
> > >      <point x="3" y="8"/>
> > >      <point x="3" y="10"/>
> > >   </set>
> > >   <set id="2">
> > >      <point x="1" y="2"/>
> > >      <point x="1" y="5"/>
> > >      <point x="1" y="5"/>
> > >      <point x="1" y="7"/>
> > >      <point x="2" y="2"/>
> > >      <point x="3" y="2"/>
> > >      <point x="3" y="4"/>
> > >      <point x="3" y="6"/>
> > >   </set>
> > >   <set id="n">
> > >      <point x="1" y="2"/>
> > >      <point x="1" y="5"/>
> > >      <point x="1" y="7"/>
> > >      <point x="2" y="3"/>
> > >      <point x="2" y="3"/>
> > >      <point x="2" y="5"/>
> > >      <point x="3" y="3"/>
> > >   </set>
> > > </root>
> > >
> > >
> > > --
> > > Cheers,
> > > Dimitre Novatchev
> > > ---------------------------------------
> > > Truly great madness cannot be achieved without significant
intelligence.
> > > ---------------------------------------
> > > To invent, you need a good imagination and a pile of junk
> > > -------------------------------------
> > > You've achieved success in your field when you don't know whether
> > > what you're doing is work or play

Current Thread