Project

Profile

Help

Bug #6095

closed

accumulator-rule match with variables leads to java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0

Added by Martin Honnen over 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
XSLT conformance
Sprint/Milestone:
-
Start date:
2023-06-24
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
10, 11, 12
Fix Committed on Branch:
11, 12, trunk
Fixed in Maintenance Release:
Platforms:
.NET, Java

Description

While playing with some different match patterns for an accumulator I have run into an internal error in Saxon (tested with Java HE 12.2, 11.5 and 10.9 as well as with SaxonCS 12.2 and 11.5):

XSLT:

<?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:param name="limit" as="xs:integer" select="5"/>

  <xsl:accumulator name="node-count" as="xs:integer" initial-value="0">
    <xsl:accumulator-rule match="node()[$value le $limit or $value gt $limit]" select="$value + 1"/>
  </xsl:accumulator>

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

  <xsl:template match="node()">
    <xsl:message select="accumulator-before('node-count')"/>
    <xsl:next-match/>
  </xsl:template>

  <xsl:template match="/" name="xsl:initial-template">
    <xsl:copy>
      <xsl:apply-templates/>
      <xsl:comment>Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} at {current-dateTime()}</xsl:comment>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

XML (doesn't probably matter):

<?xml version="1.0" encoding="utf-8"?>
<html lang="en">
  <head>
    <title>XML sample1</title>
  </head>
  <body>
    <section>
      <h1>Test</h1>
      <section>
        <h2>Test sample</h2>
        <ul>
          <li>list item 1</li>
          <li>list item 2</li>
          <li>list item 3</li>
        </ul>
      </section>
    </section>
  </body>
</html>

Stack trace with 12.2 Java HE:

java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
        at net.sf.saxon.expr.XPathContextMinor.evaluateLocalVariable(XPathContextMinor.java:371)
        at net.sf.saxon.expr.SuppliedParameterReference$SuppliedParameterReferenceElaborator.lambda$elaborateForItem$2(SuppliedParameterReference.java:309)
        at net.sf.saxon.expr.ValueComparison$ValueComparisonElaborator.lambda$elaborateForBoolean$4(ValueComparison.java:607)
        at net.sf.saxon.expr.OrExpression$OrElaborator.lambda$elaborateForBoolean$0(OrExpression.java:173)
        at net.sf.saxon.pattern.BasePatternWithPredicate.matchesPredicate(BasePatternWithPredicate.java:137)
        at net.sf.saxon.pattern.BasePatternWithPredicate.matches(BasePatternWithPredicate.java:125)
        at net.sf.saxon.trans.rules.Rule.matches(Rule.java:239)
        at net.sf.saxon.trans.SimpleMode.ruleMatches(SimpleMode.java:758)
        at net.sf.saxon.trans.SimpleMode.searchRuleChain(SimpleMode.java:732)
        at net.sf.saxon.trans.SimpleMode.findBestRuleForNodeInfo(SimpleMode.java:640)
        at net.sf.saxon.trans.SimpleMode.getRule(SimpleMode.java:550)
        at net.sf.saxon.expr.accum.AccumulatorData.visit(AccumulatorData.java:106)
        at net.sf.saxon.expr.accum.AccumulatorData.visit(AccumulatorData.java:112)
        at net.sf.saxon.expr.accum.AccumulatorData.buildIndex(AccumulatorData.java:74)
        at net.sf.saxon.expr.accum.AccumulatorManager.getAccumulatorData(AccumulatorManager.java:127)
        at net.sf.saxon.functions.AccumulatorFn.getAccumulatorValue(AccumulatorFn.java:61)
        at net.sf.saxon.functions.AccumulatorFn.call(AccumulatorFn.java:154)
        at net.sf.saxon.expr.SystemFunctionCall$SystemFunctionCallElaborator.lambda$elaborateForPull$1(SystemFunctionCall.java:605)
        at net.sf.saxon.expr.elab.PullElaborator.lambda$elaborateForPush$0(PullElaborator.java:38)
        at net.sf.saxon.expr.instruct.MessageInstr$MessageInstrElaborator.lambda$elaborateForPush$0(MessageInstr.java:337)
        at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$1(Block.java:851)
        at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:393)
        at net.sf.saxon.trans.Mode.handleRuleNotNull(Mode.java:568)
        at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:502)
        at net.sf.saxon.expr.instruct.ApplyTemplates$ApplyTemplatesElaborator.lambda$elaborateForPush$1(ApplyTemplates.java:650)
        at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$1(Block.java:851)
        at net.sf.saxon.expr.instruct.Copy$CopyElaborator.lambda$elaborateForPush$0(Copy.java:645)
        at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:393)
        at net.sf.saxon.trans.Mode.handleRuleNotNull(Mode.java:568)
        at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:502)
        at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:684)
        at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:427)
        at net.sf.saxon.s9api.Xslt30Transformer.applyTemplates(Xslt30Transformer.java:306)
        at net.sf.saxon.Transform.processFile(Transform.java:1389)
        at net.sf.saxon.Transform.doTransform(Transform.java:879)
        at net.sf.saxon.Transform.main(Transform.java:83)
java.lang.RuntimeException: Internal error evaluating template rule  at line 16 in module file:/C:/Users/marti/OneDrive/Documents/xslt/blog-xslt-3-by-example/accumulator-message/./sheet8.xsl
        at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:403)
        at net.sf.saxon.trans.Mode.handleRuleNotNull(Mode.java:568)
        at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:502)
        at net.sf.saxon.expr.instruct.ApplyTemplates$ApplyTemplatesElaborator.lambda$elaborateForPush$1(ApplyTemplates.java:650)
        at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$1(Block.java:851)
        at net.sf.saxon.expr.instruct.Copy$CopyElaborator.lambda$elaborateForPush$0(Copy.java:645)
        at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:393)
        at net.sf.saxon.trans.Mode.handleRuleNotNull(Mode.java:568)
        at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:502)
        at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:684)
        at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:427)
        at net.sf.saxon.s9api.Xslt30Transformer.applyTemplates(Xslt30Transformer.java:306)
        at net.sf.saxon.Transform.processFile(Transform.java:1389)
        at net.sf.saxon.Transform.doTransform(Transform.java:879)
        at net.sf.saxon.Transform.main(Transform.java:83)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
        at net.sf.saxon.expr.XPathContextMinor.evaluateLocalVariable(XPathContextMinor.java:371)
        at net.sf.saxon.expr.SuppliedParameterReference$SuppliedParameterReferenceElaborator.lambda$elaborateForItem$2(SuppliedParameterReference.java:309)
        at net.sf.saxon.expr.ValueComparison$ValueComparisonElaborator.lambda$elaborateForBoolean$4(ValueComparison.java:607)
        at net.sf.saxon.expr.OrExpression$OrElaborator.lambda$elaborateForBoolean$0(OrExpression.java:173)
        at net.sf.saxon.pattern.BasePatternWithPredicate.matchesPredicate(BasePatternWithPredicate.java:137)
        at net.sf.saxon.pattern.BasePatternWithPredicate.matches(BasePatternWithPredicate.java:125)
        at net.sf.saxon.trans.rules.Rule.matches(Rule.java:239)
        at net.sf.saxon.trans.SimpleMode.ruleMatches(SimpleMode.java:758)
        at net.sf.saxon.trans.SimpleMode.searchRuleChain(SimpleMode.java:732)
        at net.sf.saxon.trans.SimpleMode.findBestRuleForNodeInfo(SimpleMode.java:640)
        at net.sf.saxon.trans.SimpleMode.getRule(SimpleMode.java:550)
        at net.sf.saxon.expr.accum.AccumulatorData.visit(AccumulatorData.java:106)
        at net.sf.saxon.expr.accum.AccumulatorData.visit(AccumulatorData.java:112)
        at net.sf.saxon.expr.accum.AccumulatorData.buildIndex(AccumulatorData.java:74)
        at net.sf.saxon.expr.accum.AccumulatorManager.getAccumulatorData(AccumulatorManager.java:127)
        at net.sf.saxon.functions.AccumulatorFn.getAccumulatorValue(AccumulatorFn.java:61)
        at net.sf.saxon.functions.AccumulatorFn.call(AccumulatorFn.java:154)
        at net.sf.saxon.expr.SystemFunctionCall$SystemFunctionCallElaborator.lambda$elaborateForPull$1(SystemFunctionCall.java:605)
        at net.sf.saxon.expr.elab.PullElaborator.lambda$elaborateForPush$0(PullElaborator.java:38)
        at net.sf.saxon.expr.instruct.MessageInstr$MessageInstrElaborator.lambda$elaborateForPush$0(MessageInstr.java:337)
        at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$1(Block.java:851)
        at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:393)
        ... 14 more
java.lang.RuntimeException: Internal error evaluating template rule  at line 21 in module file:/C:/Users/marti/OneDrive/Documents/xslt/blog-xslt-3-by-example/accumulator-message/./sheet8.xsl
        at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:403)
        at net.sf.saxon.trans.Mode.handleRuleNotNull(Mode.java:568)
        at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:502)
        at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:684)
        at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:427)
        at net.sf.saxon.s9api.Xslt30Transformer.applyTemplates(Xslt30Transformer.java:306)
        at net.sf.saxon.Transform.processFile(Transform.java:1389)
        at net.sf.saxon.Transform.doTransform(Transform.java:879)
        at net.sf.saxon.Transform.main(Transform.java:83)
Caused by: java.lang.RuntimeException: Internal error evaluating template rule  at line 16 in module file:/C:/Users/marti/OneDrive/Documents/xslt/blog-xslt-3-by-example/accumulator-message/./sheet8.xsl
        at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:403)
        at net.sf.saxon.trans.Mode.handleRuleNotNull(Mode.java:568)
        at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:502)
        at net.sf.saxon.expr.instruct.ApplyTemplates$ApplyTemplatesElaborator.lambda$elaborateForPush$1(ApplyTemplates.java:650)
        at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$1(Block.java:851)
        at net.sf.saxon.expr.instruct.Copy$CopyElaborator.lambda$elaborateForPush$0(Copy.java:645)
        at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:393)
        ... 8 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
        at net.sf.saxon.expr.XPathContextMinor.evaluateLocalVariable(XPathContextMinor.java:371)
        at net.sf.saxon.expr.SuppliedParameterReference$SuppliedParameterReferenceElaborator.lambda$elaborateForItem$2(SuppliedParameterReference.java:309)
        at net.sf.saxon.expr.ValueComparison$ValueComparisonElaborator.lambda$elaborateForBoolean$4(ValueComparison.java:607)
        at net.sf.saxon.expr.OrExpression$OrElaborator.lambda$elaborateForBoolean$0(OrExpression.java:173)
        at net.sf.saxon.pattern.BasePatternWithPredicate.matchesPredicate(BasePatternWithPredicate.java:137)
        at net.sf.saxon.pattern.BasePatternWithPredicate.matches(BasePatternWithPredicate.java:125)
        at net.sf.saxon.trans.rules.Rule.matches(Rule.java:239)
        at net.sf.saxon.trans.SimpleMode.ruleMatches(SimpleMode.java:758)
        at net.sf.saxon.trans.SimpleMode.searchRuleChain(SimpleMode.java:732)
        at net.sf.saxon.trans.SimpleMode.findBestRuleForNodeInfo(SimpleMode.java:640)
        at net.sf.saxon.trans.SimpleMode.getRule(SimpleMode.java:550)
        at net.sf.saxon.expr.accum.AccumulatorData.visit(AccumulatorData.java:106)
        at net.sf.saxon.expr.accum.AccumulatorData.visit(AccumulatorData.java:112)
        at net.sf.saxon.expr.accum.AccumulatorData.buildIndex(AccumulatorData.java:74)
        at net.sf.saxon.expr.accum.AccumulatorManager.getAccumulatorData(AccumulatorManager.java:127)
        at net.sf.saxon.functions.AccumulatorFn.getAccumulatorValue(AccumulatorFn.java:61)
        at net.sf.saxon.functions.AccumulatorFn.call(AccumulatorFn.java:154)
        at net.sf.saxon.expr.SystemFunctionCall$SystemFunctionCallElaborator.lambda$elaborateForPull$1(SystemFunctionCall.java:605)
        at net.sf.saxon.expr.elab.PullElaborator.lambda$elaborateForPush$0(PullElaborator.java:38)
        at net.sf.saxon.expr.instruct.MessageInstr$MessageInstrElaborator.lambda$elaborateForPush$0(MessageInstr.java:337)
        at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$1(Block.java:851)
        at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:393)
        ... 14 more
Fatal error during transformation: java.lang.RuntimeException: Internal error evaluating template rule  at line 21 in module file:/C:/Users/marti/OneDrive/Documents/xslt/blog-xslt-3-by-example/accumulator-message/./sheet8.xsl

Stacktrace of Saxon CS 12.2:

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Saxon.Hej.expr.XPathContextMinor.evaluateLocalVariable(Int32 slot)
   at Saxon.Hej.expr.SuppliedParameterReference.SuppliedParameterReferenceElaborator.<>c__DisplayClass4_0.<elaborateForItem>b__0(XPathContext context)
   at Saxon.Hej.expr.ValueComparison.ValueComparisonElaborator.<>c__DisplayClass2_0.<elaborateForBoolean>b__1(XPathContext context)
   at Saxon.Hej.expr.OrExpression.OrElaborator.<>c__DisplayClass0_0.<elaborateForBoolean>b__0(XPathContext context)
   at Saxon.Hej.pattern.BasePatternWithPredicate.matchesPredicate(Item item, XPathContext context)
   at Saxon.Hej.pattern.BasePatternWithPredicate.matches(Item item, XPathContext context)
   at Saxon.Hej.trans.rules.Rule.matches(Item item, XPathContextMajor context)
   at Saxon.Hej.trans.SimpleMode.ruleMatches(Rule r, Item item, XPathContextMajor context, RuleSearchState pre)
   at Saxon.Hej.trans.SimpleMode.searchRuleChain(Item item, XPathContext context, Rule bestRule, RuleChain chain)
   at Saxon.Hej.trans.SimpleMode.findBestRuleForNodeInfo(NodeInfo node, XPathContext context)
   at Saxon.Hej.trans.SimpleMode.getRule(Item item, XPathContext context)
   at Saxon.Hej.expr.accum.AccumulatorData.visit(NodeInfo node, Sequence value, XPathContext context)
   at Saxon.Hej.expr.accum.AccumulatorData.visit(NodeInfo node, Sequence value, XPathContext context)
   at Saxon.Hej.expr.accum.AccumulatorData.buildIndex(NodeInfo doc, XPathContext context)
   at Saxon.Hej.expr.accum.AccumulatorManager.getAccumulatorData(TreeInfo doc, Accumulator acc, XPathContext context)
   at Saxon.Hej.functions.AccumulatorFn.getAccumulatorValue(String name, Phase phase, XPathContext context)
   at Saxon.Hej.functions.AccumulatorFn.call(XPathContext context, Sequence[] arguments)
   at Saxon.Hej.expr.SystemFunctionCall.SystemFunctionCallElaborator.<>c__DisplayClass1_0.<elaborateForPull>b__1(XPathContext context)
   at Saxon.Hej.expr.elab.PullElaborator.<>c__DisplayClass2_0.<elaborateForPush>b__0(Outputter out, XPathContext context)
   at Saxon.Hej.expr.instruct.MessageInstr.MessageInstrElaborator.<>c__DisplayClass0_0.<elaborateForPush>b__0(Outputter out, XPathContext context)
   at Saxon.Hej.expr.instruct.Block.BlockElaborator.<>c__DisplayClass3_1.<elaborateForPush>b__1(Outputter out, XPathContext context)
   at Saxon.Hej.expr.instruct.TemplateRule.applyLeavingTail(Outputter output, XPathContext context)
System.Exception: Internal error evaluating template rule  at line 16 in module file:///C:/Users/marti/OneDrive/Documents/xslt/blog-xslt-3-by-example/accumulator-message/sheet8.xsl
 ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Saxon.Hej.expr.XPathContextMinor.evaluateLocalVariable(Int32 slot)
   at Saxon.Hej.expr.SuppliedParameterReference.SuppliedParameterReferenceElaborator.<>c__DisplayClass4_0.<elaborateForItem>b__0(XPathContext context)
   at Saxon.Hej.expr.ValueComparison.ValueComparisonElaborator.<>c__DisplayClass2_0.<elaborateForBoolean>b__1(XPathContext context)
   at Saxon.Hej.expr.OrExpression.OrElaborator.<>c__DisplayClass0_0.<elaborateForBoolean>b__0(XPathContext context)
   at Saxon.Hej.pattern.BasePatternWithPredicate.matchesPredicate(Item item, XPathContext context)
   at Saxon.Hej.pattern.BasePatternWithPredicate.matches(Item item, XPathContext context)
   at Saxon.Hej.trans.rules.Rule.matches(Item item, XPathContextMajor context)
   at Saxon.Hej.trans.SimpleMode.ruleMatches(Rule r, Item item, XPathContextMajor context, RuleSearchState pre)
   at Saxon.Hej.trans.SimpleMode.searchRuleChain(Item item, XPathContext context, Rule bestRule, RuleChain chain)
   at Saxon.Hej.trans.SimpleMode.findBestRuleForNodeInfo(NodeInfo node, XPathContext context)
   at Saxon.Hej.trans.SimpleMode.getRule(Item item, XPathContext context)
   at Saxon.Hej.expr.accum.AccumulatorData.visit(NodeInfo node, Sequence value, XPathContext context)
   at Saxon.Hej.expr.accum.AccumulatorData.visit(NodeInfo node, Sequence value, XPathContext context)
   at Saxon.Hej.expr.accum.AccumulatorData.buildIndex(NodeInfo doc, XPathContext context)
   at Saxon.Hej.expr.accum.AccumulatorManager.getAccumulatorData(TreeInfo doc, Accumulator acc, XPathContext context)
   at Saxon.Hej.functions.AccumulatorFn.getAccumulatorValue(String name, Phase phase, XPathContext context)
   at Saxon.Hej.functions.AccumulatorFn.call(XPathContext context, Sequence[] arguments)
   at Saxon.Hej.expr.SystemFunctionCall.SystemFunctionCallElaborator.<>c__DisplayClass1_0.<elaborateForPull>b__1(XPathContext context)
   at Saxon.Hej.expr.elab.PullElaborator.<>c__DisplayClass2_0.<elaborateForPush>b__0(Outputter out, XPathContext context)
   at Saxon.Hej.expr.instruct.MessageInstr.MessageInstrElaborator.<>c__DisplayClass0_0.<elaborateForPush>b__0(Outputter out, XPathContext context)
   at Saxon.Hej.expr.instruct.Block.BlockElaborator.<>c__DisplayClass3_1.<elaborateForPush>b__1(Outputter out, XPathContext context)
   at Saxon.Hej.expr.instruct.TemplateRule.applyLeavingTail(Outputter output, XPathContext context)
   --- End of inner exception stack trace ---
   at Saxon.Hej.expr.instruct.TemplateRule.applyLeavingTail(Outputter output, XPathContext context)
   at Saxon.Hej.trans.Mode.handleRuleNotNull(Rule rule, TraceListener traceListener, XPathContextMajor context, Item item, TemplateRule previousTemplate, ParameterSet parameters, ParameterSet tunnelParameters, Outputter output)
   at Saxon.Hej.trans.Mode.applyTemplates(ParameterSet parameters, ParameterSet tunnelParameters, NodeInfo separator, Outputter output, XPathContextMajor context, Location locationId)
   at Saxon.Hej.expr.instruct.ApplyTemplates.ApplyTemplatesElaborator.<>c__DisplayClass1_2.<elaborateForPush>b__1(Outputter output, XPathContext context)
   at Saxon.Hej.expr.instruct.Block.BlockElaborator.<>c__DisplayClass3_1.<elaborateForPush>b__1(Outputter out, XPathContext context)
   at Saxon.Hej.expr.instruct.Copy.CopyElaborator.<>c__DisplayClass0_0.<elaborateForPush>b__0(Outputter output, XPathContext context)
   at Saxon.Hej.expr.instruct.TemplateRule.applyLeavingTail(Outputter output, XPathContext context)
System.Exception: Internal error evaluating template rule  at line 21 in module file:///C:/Users/marti/OneDrive/Documents/xslt/blog-xslt-3-by-example/accumulator-message/sheet8.xsl
 ---> System.Exception: Internal error evaluating template rule  at line 16 in module file:///C:/Users/marti/OneDrive/Documents/xslt/blog-xslt-3-by-example/accumulator-message/sheet8.xsl
 ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Saxon.Hej.expr.XPathContextMinor.evaluateLocalVariable(Int32 slot)
   at Saxon.Hej.expr.SuppliedParameterReference.SuppliedParameterReferenceElaborator.<>c__DisplayClass4_0.<elaborateForItem>b__0(XPathContext context)
   at Saxon.Hej.expr.ValueComparison.ValueComparisonElaborator.<>c__DisplayClass2_0.<elaborateForBoolean>b__1(XPathContext context)
   at Saxon.Hej.expr.OrExpression.OrElaborator.<>c__DisplayClass0_0.<elaborateForBoolean>b__0(XPathContext context)
   at Saxon.Hej.pattern.BasePatternWithPredicate.matchesPredicate(Item item, XPathContext context)
   at Saxon.Hej.pattern.BasePatternWithPredicate.matches(Item item, XPathContext context)
   at Saxon.Hej.trans.rules.Rule.matches(Item item, XPathContextMajor context)
   at Saxon.Hej.trans.SimpleMode.ruleMatches(Rule r, Item item, XPathContextMajor context, RuleSearchState pre)
   at Saxon.Hej.trans.SimpleMode.searchRuleChain(Item item, XPathContext context, Rule bestRule, RuleChain chain)
   at Saxon.Hej.trans.SimpleMode.findBestRuleForNodeInfo(NodeInfo node, XPathContext context)
   at Saxon.Hej.trans.SimpleMode.getRule(Item item, XPathContext context)
   at Saxon.Hej.expr.accum.AccumulatorData.visit(NodeInfo node, Sequence value, XPathContext context)
   at Saxon.Hej.expr.accum.AccumulatorData.visit(NodeInfo node, Sequence value, XPathContext context)
   at Saxon.Hej.expr.accum.AccumulatorData.buildIndex(NodeInfo doc, XPathContext context)
   at Saxon.Hej.expr.accum.AccumulatorManager.getAccumulatorData(TreeInfo doc, Accumulator acc, XPathContext context)
   at Saxon.Hej.functions.AccumulatorFn.getAccumulatorValue(String name, Phase phase, XPathContext context)
   at Saxon.Hej.functions.AccumulatorFn.call(XPathContext context, Sequence[] arguments)
   at Saxon.Hej.expr.SystemFunctionCall.SystemFunctionCallElaborator.<>c__DisplayClass1_0.<elaborateForPull>b__1(XPathContext context)
   at Saxon.Hej.expr.elab.PullElaborator.<>c__DisplayClass2_0.<elaborateForPush>b__0(Outputter out, XPathContext context)
   at Saxon.Hej.expr.instruct.MessageInstr.MessageInstrElaborator.<>c__DisplayClass0_0.<elaborateForPush>b__0(Outputter out, XPathContext context)
   at Saxon.Hej.expr.instruct.Block.BlockElaborator.<>c__DisplayClass3_1.<elaborateForPush>b__1(Outputter out, XPathContext context)
   at Saxon.Hej.expr.instruct.TemplateRule.applyLeavingTail(Outputter output, XPathContext context)
   --- End of inner exception stack trace ---
   at Saxon.Hej.expr.instruct.TemplateRule.applyLeavingTail(Outputter output, XPathContext context)
   at Saxon.Hej.trans.Mode.handleRuleNotNull(Rule rule, TraceListener traceListener, XPathContextMajor context, Item item, TemplateRule previousTemplate, ParameterSet parameters, ParameterSet tunnelParameters, Outputter output)
   at Saxon.Hej.trans.Mode.applyTemplates(ParameterSet parameters, ParameterSet tunnelParameters, NodeInfo separator, Outputter output, XPathContextMajor context, Location locationId)
   at Saxon.Hej.expr.instruct.ApplyTemplates.ApplyTemplatesElaborator.<>c__DisplayClass1_2.<elaborateForPush>b__1(Outputter output, XPathContext context)
   at Saxon.Hej.expr.instruct.Block.BlockElaborator.<>c__DisplayClass3_1.<elaborateForPush>b__1(Outputter out, XPathContext context)
   at Saxon.Hej.expr.instruct.Copy.CopyElaborator.<>c__DisplayClass0_0.<elaborateForPush>b__0(Outputter output, XPathContext context)
   at Saxon.Hej.expr.instruct.TemplateRule.applyLeavingTail(Outputter output, XPathContext context)
   --- End of inner exception stack trace ---
   at Saxon.Hej.expr.instruct.TemplateRule.applyLeavingTail(Outputter output, XPathContext context)
   at Saxon.Hej.trans.Mode.handleRuleNotNull(Rule rule, TraceListener traceListener, XPathContextMajor context, Item item, TemplateRule previousTemplate, ParameterSet parameters, ParameterSet tunnelParameters, Outputter output)
   at Saxon.Hej.trans.Mode.applyTemplates(ParameterSet parameters, ParameterSet tunnelParameters, NodeInfo separator, Outputter output, XPathContextMajor context, Location locationId)
   at Saxon.Hej.trans.XsltController.applyTemplates(Sequence source, Receiver out)
   at Saxon.Hej.s9api.AbstractXsltTransformer.applyTemplatesToSource(Source source, Receiver out)
   at Saxon.Hej.s9api.Xslt30Transformer.applyTemplates(Source source, Destination destination)
   at Saxon.Hej.Transform.processFile(Source source, XsltExecutable sheet, File outputFile, CommandLineOptions options)
   at Saxon.Hej.Transform.doTransform(String[] args)
Fatal error during transformation: Exception: Internal error evaluating template rule  at line 21 in module file:///C:/Users/marti/OneDrive/Documents/xslt/blog-xslt-3-by-example/accumulator-message/sheet8.xsl
Exiting with code 2
Actions #1

Updated by Michael Kay over 1 year ago

Problem reproduced as test case accumulator-091.

I think the correct outcome for this stylesheet is a static error saying that the variable reference $value is not in-scope within the match pattern. The rules for accumulators say that the static context for the select expression includes the additional variable $value; there is no such statement that extends the context for the match pattern in a similar way.

(What is actually happening is that at compile time, we treat $value as being present in the static context for the match attribute, but at execution time, we don't supply a value.)

Actions #2

Updated by Michael Kay over 1 year ago

The mechanism used to bind the variable $value in xsl:accumulator-rule/@select is basically that StyleElement.bindLocalVariable(), which calls StyleElement.hasImplicitBinding(), which in the case of XSLAccumulatorRule recognises $value as a special case. Unfortunately this mechanism doesn't easily allow the static context for @match to be different from that for @select.

Actions #3

Updated by Michael Kay over 1 year ago

  • Status changed from New to In Progress

Resolved as follows: the ExpressionContext already knows which attribute contains the expression being parsed. Pass this information through StyleElement.bindLocalVariable to StyleElement.hasImplicitBinding; the implementation in XSLAccumulatorRule.hasImplicitBinding can then make its special logic for binding $value work only when the attribute name is Q{}select.

Actions #4

Updated by Michael Kay over 1 year ago

The initial fix breaks test accumulator-043, where the reference to $value is not in the select attribute, but in a descendant instruction within the sequence constructor of the xsl:accumulator-rule element.

Actions #5

Updated by Michael Kay over 1 year ago

  • Status changed from In Progress to Resolved
  • Assignee set to Michael Kay
  • Fix Committed on Branch 11, 12, trunk added
Actions #6

Updated by O'Neil Delpratt over 1 year ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 12.3 added

Bug fix applied in the Saxon 12.3 maintenance release.

Actions #7

Updated by O'Neil Delpratt over 1 year ago

  • Status changed from Closed to Resolved

Leaving this bug issue as resolved until resolved against Saxon 11.

Actions #8

Updated by Debbie Lockett about 1 year ago

  • Status changed from Resolved to Closed
  • Fixed in Maintenance Release 11.6 added

Bug fix applied in the Saxon 11.6 maintenance release.

Please register to edit this issue

Also available in: Atom PDF