Project

Profile

Help

No namespace top level accumulator element with nested xsl:accumulator-rule elements doesn't raise ERR XTSE0130 but causes java.lang.ClassCastException: net.sf.saxon.style.LiteralResultElement cannot be cast to net.sf.saxon.style.XSLAccumulator

Added by Martin Honnen about 5 years ago

Another oddity I run into today based on the StackOverflow question is that Saxon 9.9.1.5 HE on trying to run the code below from the command line (against any XML input) doesn't raise a static error ERR XTSE0130 due to the accumulator element in no namespace but rather gives the error

java.lang.ClassCastException: net.sf.saxon.style.LiteralResultElement cannot be cast to net.sf.saxon.style.XSLAccumulator
        at net.sf.saxon.style.XSLAccumulatorRule.hasImplicitBinding(XSLAccumulatorRule.java:131)
        at net.sf.saxon.style.StyleElement.bindLocalVariable(StyleElement.java:2628)
        at net.sf.saxon.style.StyleElement.bindVariable(StyleElement.java:2599)
        at net.sf.saxon.style.ExpressionContext.bindVariable(ExpressionContext.java:218)
        at net.sf.saxon.expr.parser.XPathParser.parseVariableReference(XPathParser.java:2412)
        at net.sf.saxon.expr.parser.XPathParser.parseBasicStep(XPathParser.java:2185)
        at net.sf.saxon.expr.parser.XPathParser.parseStepExpression(XPathParser.java:2076)
        at net.sf.saxon.expr.parser.XPathParser.parseRelativePath(XPathParser.java:1995)
        at net.sf.saxon.expr.parser.XPathParser.parsePathExpression(XPathParser.java:1957)
        at net.sf.saxon.expr.parser.XPathParser.parseSimpleMappingExpression(XPathParser.java:1971)
        at net.sf.saxon.expr.parser.XPathParser.parseUnaryExpression(XPathParser.java:1824)
        at net.sf.saxon.expr.parser.XPathParser.parseExprSingle(XPathParser.java:753)
        at net.sf.saxon.expr.parser.XPathParser.parseExpression(XPathParser.java:660)
        at net.sf.saxon.expr.parser.XPathParser.parse(XPathParser.java:522)
        at net.sf.saxon.expr.parser.ExpressionTool.make(ExpressionTool.java:107)
        at net.sf.saxon.style.StyleElement.makeExpression(StyleElement.java:735)
        at net.sf.saxon.style.XSLAccumulatorRule.prepareAttributes(XSLAccumulatorRule.java:44)
        at net.sf.saxon.style.StyleElement.processAttributes(StyleElement.java:618)
        at net.sf.saxon.style.StyleElement.processAllAttributes(StyleElement.java:551)
        at net.sf.saxon.style.StyleElement.lambda$processAllAttributes$1(StyleElement.java:554)
        at net.sf.saxon.om.SequenceIterator.forEachOrFail(SequenceIterator.java:128)
        at net.sf.saxon.style.StyleElement.processAllAttributes(StyleElement.java:552)
        at net.sf.saxon.style.PrincipalStylesheetModule.processAllAttributes(PrincipalStylesheetModule.java:583)
        at net.sf.saxon.style.PrincipalStylesheetModule.preprocess(PrincipalStylesheetModule.java:367)
        at net.sf.saxon.style.Compilation.compilePackage(Compilation.java:286)
        at net.sf.saxon.style.StylesheetModule.loadStylesheet(StylesheetModule.java:222)
        at net.sf.saxon.style.Compilation.compileSingletonPackage(Compilation.java:107)
        at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:785)
        at net.sf.saxon.Transform.doTransform(Transform.java:741)
        at net.sf.saxon.Transform.main(Transform.java:80)
Fatal error during transformation: java.lang.ClassCastException: net.sf.saxon.style.LiteralResultElement cannot be cast to net.sf.saxon.style.XSLAccumulator
<?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">
    
    <accumulator name="a1" as="xs:integer" initial-value="0">
        <xsl:accumulator-rule match="foo" select="0"/>
        <xsl:accumulator-rule match="foo/*" select="$value + 1"/>
    </accumulator>
    
    <xsl:mode on-no-match="shallow-copy" use-accumulators="a1"/>
    
</xsl:stylesheet>

I am not sure the raising of that static error is mandatory but I guess the ClassCastException is not meant to be the planned notification to the stylesheet author of the not allowed top level element in no namespace.


    (1-2/2)

    Please register to reply