xsl-list
[Top] [All Lists]

Re: [xsl] RE: Is xsl:for-each "syntactic sugar"?

2010-05-07 18:06:37
On 07/05/2010 23:34, Costello, Roger L. wrote:
I do not believe that this task can be accomplished using xsl:for-each.

why not?

> Do you agree?

No.

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


<xsl:template match="BankTransactions">
<xsl:for-each select="Transaction">
<xsl:value-of select="sum(.|preceding-sibling::*),' '"/>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>


$ saxon9 rc.xml rc.xsl
<?xml version="1.0" encoding="UTF-8"?>95  92.5  102.5  95

It's (probably, unless Michael rewrites it aggressively behind the scenes) an algorithm with theoretically greater computational complexity than the versions using + (order n squared instead of linear) but it's a lot easier to read and write and unless there are hundreds of siblings the complexity may not matter,


  <xsl:if test="following-sibling::Transaction">
<xsl:apply-templates select="following-sibling::Transaction[1]">


the xsl:if isn't needed as if the test is false the apply-templates wouldn't do anything anyway.

As Dimitre has already said, you can't give general advice about which kind of algorithm is superior, it depends a lot on whether the system does tail recursion elimination on the explicitly recursive forms, so like most optimisation questions the answers are system specific.

David

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--