xsl-list
[Top] [All Lists]

RE: [xsl] accumulators

2013-04-20 13:07:05
Yes, the example I sent does not make any sense after reading the spec
properly. 

-----Original Message-----
From: Michael Kay [mailto:mike(_at_)saxonica(_dot_)com] 
Sent: Saturday, April 20, 2013 6:41 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] accumulators

Like xsl:key, accumulators apply to every document, but when you evaluate
the accumulator function, you get the value applicable to the context node.
In all your calls of the accumulator function, the context node is the root
of the principal source document.

Accumulators are strictly functional: the value is a function of the context
node. If you call the function twice and the context node is the same for
both calls, you will get the same answer.

Michael Kay
Saxonica


On 19 Apr 2013, at 22:04, Jakub Malý wrote:

Hi,
I am fiddling with XSLT accumulators in the new version of Saxon. 
I first looked at the examples in the spec and thought that this might 
work (and output 01210), but it doesn't:

<?xml version="1.0" encoding="UTF-8"?>

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

      <xsl:accumulator name="f:my-var" as="xs:integer" initial-value="0" >
              <xsl:accumulator-rule match="f:inc" new-value="$value + 1"/>
              <xsl:accumulator-rule match="f:dec" new-value="$value - 1"/>
      </xsl:accumulator>
      
      <xsl:variable name="f:control-inc" as="element()*">
              <f:inc/>
      </xsl:variable>
      <xsl:variable name="f:control-dec" as="element()*">
              <f:dec/>
      </xsl:variable>
      
      <xsl:template match="/">
              <xsl:value-of select="f:my-var()" />
              <xsl:apply-templates select="$f:control-inc"/>
              <xsl:value-of select="f:my-var()" />
              <xsl:apply-templates select="$f:control-inc"/>
              <xsl:value-of select="f:my-var()" />
              <xsl:apply-templates select="$f:control-dec"/>
              <xsl:value-of select="f:my-var()" />
              <xsl:apply-templates select="$f:control-dec"/>
              <xsl:value-of select="f:my-var()" />
      </xsl:template>
</xsl:stylesheet>

So I read the spec and I guess I understand why. 
Accumulator rule is not triggered by calling apply-templates, it does 
not matter how many times the same node is processed, the value for 
the accumulator will be the same.

Do accumulators work only for the nodes from the source document or 
also for nodes from documents loaded using doc() or document()?

Jakub.



--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--


<Prev in Thread] Current Thread [Next in Thread>