xsl-list
[Top] [All Lists]

[xsl] [Accumulators] Another stupid question

2020-10-06 15:57:47
Hello !

I have another question with accumulators. I use accumulators to calculate block height, and then to calculate block locations (y).

I have this XSL for a repro...

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:xs="http://www.w3.org/2001/XMLSchema";
  xmlns:private="top:marchand"
  exclude-result-prefixes="#all"
  version="3.0">

  <xsl:output method="xml" indent="true"/>

  <xsl:mode on-no-match="shallow-copy" use-accumulators="#all"/>

  <xsl:accumulator name="blockHeight" as="xs:double" initial-value="0.0">
    <xsl:accumulator-rule match="page">
      <xsl:message>Reset block height to 3.2</xsl:message>
      <xsl:sequence select="3.2"/>
    </xsl:accumulator-rule>
    <xsl:accumulator-rule match="private:block">
      <xsl:message>Adding block height {@id} : {@height}</xsl:message>
      <xsl:sequence select="$value + xs:double(@height)"/>
    </xsl:accumulator-rule>
  </xsl:accumulator>

  <xsl:template match="block">
    <xsl:variable name="height" as="xs:double" select="3.5"/>
    <!-- produce some output -->
    <xsl:variable name="TempTree" as="element(private:block)">
      <private:block height="{$height}"/>
    </xsl:variable>
    <xsl:apply-templates select="$TempTree"/>
    <xsl:copy>
      <xsl:attribute name="y" select="accumulator-after('blockHeight')"/>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="private:block">
    <xsl:message>private:block matched</xsl:message>
  </xsl:template>

  <xsl:template name="xsl:initial-template">
    <xsl:variable name="content" as="document-node()">
      <xsl:document>
        <doc>
          <page id="p1">
            <block id="b1">
              <!-- arbitrary content -->
            </block>
            <block id="b2">
              <!-- another arbitrary content -->
            </block>
          </page>
          <page id="p2">
            <block id="b3">
              <!-- arbitrary content -->
            </block>
            <block id="b4">
              <!-- another arbitrary content -->
            </block>
          </page>
        </doc>
      </xsl:document>
    </xsl:variable>
    <xsl:apply-templates select="$content"/>
  </xsl:template>
</xsl:stylesheet>

When I run this XSL on the sample XML, I have messages displayed : "Reset block height to 3.2", "private:block matched", but never the "Adding block height..."

According to specification [1], I expect private:block matches accumulator rule, and accumulator value being augmented by block/@height.

What am I doing wrong ?

Thanks in advance,
Christophe

[1] : 18.2.2 https://www.w3.org/TR/xslt-30/#applicability-of-accumulators list item 1
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

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