Bug #4724
closedxsl:iterator/xsl:param is not accepted inside of xsl:accumulator-rule
100%
Description
On Slack an issue was raised by Tom Hillmann about the use of the $value
variable of an accumulator in the declaration of an xsl:param
inside of an xsl:iterate
.
I think this is a bug in Saxon Java, I have reduced it to:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:accumulator name="iterate-value-test" as="xs:integer" initial-value="0">
<xsl:accumulator-rule match="foo">
<xsl:iterate select="1">
<xsl:param name="test" select="$value"/>
<xsl:on-completion select="$test"/>
</xsl:iterate>
</xsl:accumulator-rule>
</xsl:accumulator>
<xsl:mode on-no-match="shallow-copy" use-accumulators="iterate-value-test"/>
<xsl:template match="foo">
<xsl:copy>
<xsl:attribute name="accumulator-test" select="accumulator-before('iterate-value-test')"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/" name="xsl:initial-template">
<xsl:next-match/>
<xsl:comment xmlns:saxon="http://saxon.sf.net/">Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} {system-property('Q{http://saxon.sf.net/}platform')}</xsl:comment>
</xsl:template>
</xsl:stylesheet>
On compilation that gives an error
Error at xsl:param on line 11 column 57 of iterate-accumulator-rule-test1.xsl: XTSE0010 Local variable must be declared within a template or function
Sample input
<root>
<foo>foo 1</foo>
</root>
The code runs fine with xslt3
/Saxon-JS 2 and Node.
The test case
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:accumulator name="iterate-value-test" as="xs:integer" initial-value="0">
<xsl:accumulator-rule match="foo">
<xsl:iterate select="1">
<xsl:sequence select="$value"/>
</xsl:iterate>
</xsl:accumulator-rule>
</xsl:accumulator>
<xsl:mode on-no-match="shallow-copy" use-accumulators="iterate-value-test"/>
<xsl:template match="foo">
<xsl:copy>
<xsl:attribute name="accumulator-test" select="accumulator-before('iterate-value-test')"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/" name="xsl:initial-template">
<xsl:next-match/>
<xsl:comment xmlns:saxon="http://saxon.sf.net/">Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} {system-property('Q{http://saxon.sf.net/}platform')}</xsl:comment>
</xsl:template>
</xsl:stylesheet>
runs fine with both Saxon Java and Saxon-JS 2 so it seems the $value
is not correctly set up in Saxon Java for the local parameter binding environment.
Updated by Michael Kay over 3 years ago
Created XSLT3 test case accumulator-082.
Updated by Michael Kay over 3 years ago
XSLAcccumulator.getSlotManager()
returns null. Can it really be the case that local variables within an accumulator rule don't work at all?
(Note: it's nothing to do with the use of $value. The failure also occurs if we write <xsl:param select="2"/>
Updated by Michael Kay over 3 years ago
Added various tests for local variables within an accumulator rule works fine (tests accumulator-083, -084, -085). They all work fine. It's only xsl:param that fails, because the handling of xsl:param depends on what construct it appears in.
Updated by Michael Kay over 3 years ago
- Status changed from New to In Progress
- Assignee set to Michael Kay
- Priority changed from Low to Normal
It seems to be possible to make progress on this as follows. In XSLAcccumulator
:
(a) make the slotManager (aka StackframeMap) a property of the XSLAcccumulator
object
(b) allocate it during XSLAcccumulator.validate()
(c) use it (instead of allocating it) during XSLAcccumulator.compileDeclaration()
(d) return it from XSLAcccumulator.getSlotManager()
Updated by Michael Kay over 3 years ago
- Subject changed from accumulator variable $value not known in xsl:param/@select of xsl:iterator inside of xsl:accumulator-rule to xsl:iterator/xsl:param is not accepted inside of xsl:accumulator-rule
- Status changed from In Progress to Resolved
- Applies to branch trunk added
- Fix Committed on Branch 10, trunk added
Patch committed.
Updated by O'Neil Delpratt over 3 years ago
Bug fix applied in the Saxon 10.3 maintenance release
Updated by O'Neil Delpratt over 3 years ago
- Status changed from Resolved to Closed
- % Done changed from 0 to 100
- Fixed in Maintenance Release 10.3 added
Please register to edit this issue