Project

Profile

Help

Bug #2450

closed

Unexpected result using w3c accumulator sample

Added by Philip Fearon over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
XSLT conformance
Sprint/Milestone:
Start date:
2015-08-31
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
9.6
Fix Committed on Branch:
9.6
Fixed in Maintenance Release:
Platforms:

Description

I'm learning use of XSLT 3.0 accumulators by going through the w3c examples, but I'm getting unexpected output using Saxon 9.6.0.3 PE.

In the example 'Output Hierarchic Section Numbers' - I'm using the following input:

<doc>
  <section>[1]
    <section>[1.1]</section>
    <section>[1.2]</section>
    <section>[1.3]
      <section>[1.3.1]</section>
      <section>[1.3.2]</section>
    </section>       
  </section>
</doc>

Here's the XSLT (the same as the w3c example code - except that the 'accumulator' function name has been substituted with 'accumulator-before')

<?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" exclude-result-prefixes="xs" version="3.0">

  <xsl:accumulator name="section-nr" as="xs:integer*" initial-value="0">
    <xsl:accumulator-rule match="section" phase="start" 
      select="0, head($value)+1, tail($value)"/>
    <xsl:accumulator-rule match="section" phase="end" select="tail($value) (:pop:)"/>
  </xsl:accumulator>

  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="section">
    <p>
      <xsl:value-of select="reverse(tail(accumulator-before('section-nr')))" 
        separator="."/>
    </p>
    <xsl:apply-templates/>
  </xsl:template>

</xsl:stylesheet>

The XML output I get is below:

<?xml version="1.0" encoding="UTF-8"?><doc>
  <p>1</p>[1]
  <p>1.1</p>[1.1]
  <p>1.2</p>[1.2]
  <p>1.3</p>[1.3]
  <p>1.3.1</p>[1.3.1]
  <p/>[1.3.2]           
</doc>

The unexpected bit is with the last 'p' element - it has no '1.3.2' text content. Curiously, if I add another section (1.3.3), then all p element text content appears as expected (including 1.3.3)

The standard output from Saxon is given below for info:

Saxon-PE 9.6.0.3J from Saxonica

Java version 1.8.0_25

Using license serial number *******

Stylesheet compilation time: 237.126943ms

Processing file:/Users/philipfearon/Documents/xslt-samples/accumulator-test.xml

Using parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser

Building tree for file:/Users/philipfearon/Documents/xslt-samples/accumulator-test.xml using class net.sf.saxon.tree.tiny.TinyBuilder

Tree built in 3.054788ms

Tree size: 22 nodes, 44 characters, 0 attributes

Execution time: 37.320784ms

Memory used: 45693584

NamePool contents: 3 entries in 3 chains. 6 URIs

Please register to edit this issue

Also available in: Atom PDF