Project

Profile

Help

ClassCastException: net.sf.saxon.expr.instruct.CopyOf cannot be cast to net.sf.saxon.expr.AxisExpression

Added by Martin Honnen about 4 years ago

In a rather complicated setup of using XSLT to transform a Schematron schema to streamable XSLT and then run that against an input document to be validated against the Schematron schema I run into a java.lang.ClassCastException: net.sf.saxon.expr.instruct.CopyOf cannot be cast to net.sf.saxon.expr.AxisExpression with both Saxon 10.2 EE and 9.9.1.7 EE.

The stack trace is

java.lang.ClassCastException: net.sf.saxon.expr.instruct.CopyOf cannot be cast to net.sf.saxon.expr.AxisExpression
        at net.sf.saxon.expr.SlashExpression.lambda$iterate$0(SlashExpression.java:948)
        at net.sf.saxon.expr.MappingIterator.next(MappingIterator.java:60)
        at net.sf.saxon.om.SequenceIterator.forEachOrFail(SequenceIterator.java:135)
        at net.sf.saxon.expr.Expression.process(Expression.java:949)
        at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:748)
        at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:752)
        at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:142)
        at net.sf.saxon.expr.instruct.ForEach.lambda$processLeavingTail$0(ForEach.java:526)
        at net.sf.saxon.om.SequenceIterator.forEachOrFail(SequenceIterator.java:136)
        at net.sf.saxon.expr.instruct.ForEach.processLeavingTail(ForEach.java:526)
        at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:142)
        at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:352)
        at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:298)
        at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:142)
        at net.sf.saxon.expr.LetExpression.process(LetExpression.java:625)
        at com.saxonica.ee.stream.adjunct.LetExpressionAdjunct$1$1.close(LetExpressionAdjunct.java:112)
        at com.saxonica.ee.stream.feed.ItemFeed.close(ItemFeed.java:272)
        at com.saxonica.ee.stream.feed.ComplexNodeEventFeed.close(ComplexNodeEventFeed.java:130)
        at com.saxonica.ee.stream.feed.ItemFeed.close(ItemFeed.java:272)
        at com.saxonica.ee.stream.watch.ApplyTemplatesAction.close(ApplyTemplatesAction.java:345)
        at com.saxonica.ee.stream.watch.Trigger.close(Trigger.java:125)
        at com.saxonica.ee.stream.watch.WatchManager.endDocument(WatchManager.java:585)
        at net.sf.saxon.event.ProxyReceiver.endDocument(ProxyReceiver.java:121)
        at net.sf.saxon.event.ReceivingContentHandler.endDocument(ReceivingContentHandler.java:268)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endDocument(AbstractSAXParser.java:745)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
        at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:439)
        at net.sf.saxon.event.Sender.send(Sender.java:168)
        at net.sf.saxon.trans.XsltController.applyStreamingTemplates(XsltController.java:950)
        at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:352)
        at net.sf.saxon.s9api.Xslt30Transformer.applyTemplates(Xslt30Transformer.java:286)
        at net.sf.saxon.Transform.processFile(Transform.java:1313)
        at net.sf.saxon.Transform.doTransform(Transform.java:853)
        at net.sf.saxon.Transform.main(Transform.java:82)
Fatal error during transformation: java.lang.ClassCastException: net.sf.saxon.expr.instruct.CopyOf cannot be cast to net.sf.saxon.expr.AxisExpression

A reduced but somehow still convoluted test file is

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform xmlns:error="https://doi.org/10.5281/zenodo.1495494#error"
               xmlns:sch="http://purl.oclc.org/dsdl/schematron"
               xmlns:schxslt="https://doi.org/10.5281/zenodo.1495494"
               xmlns:schxslt-api="https://doi.org/10.5281/zenodo.1495494#api"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
               version="3.0"><!--
      Schematron validation stylesheet created with SchXslt 1.4.6 running
      XSLT processor SAXON EE 10.2 by Saxonica.
    -->
   <xsl:import xmlns:mf="http://example.com/mf"
               xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
               href="compile-for-svrl.xsl"/>
   <xsl:mode xmlns:mf="http://example.com/mf"
             xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
             use-accumulators="position"/>
   <xsl:output indent="yes"/>
   <xsl:mode streamable="yes" use-accumulators="position"/>
   <xsl:template match="/">
      <xsl:variable name="report" as="element(schxslt:report)">
         <schxslt:report>
            <xsl:fork>
               <xsl:sequence>
                  <xsl:apply-templates select="." mode="d8e3-entry"/>
               </xsl:sequence>
            </xsl:fork>
         </schxslt:report>
      </xsl:variable>
      <xsl:variable name="schxslt:report" as="node()*">
         <xsl:for-each select="$report/schxslt:pattern">
            <xsl:sequence select="node()"/>
            <xsl:sequence select="$report/schxslt:rule[@pattern = current()/@id]/node()"/>
         </xsl:for-each>
      </xsl:variable>
      <svrl:schematron-output xmlns:mf="http://example.com/mf" xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
         <xsl:sequence select="$schxslt:report"/>
      </svrl:schematron-output>
   </xsl:template>
   <xsl:template match="text() | @*" mode="#all" priority="-10"/>
   <xsl:template match="*" mode="#all" priority="-10">
      <xsl:apply-templates mode="#current" select="@*"/>
      <xsl:apply-templates mode="#current"/>
   </xsl:template>
   <xsl:mode name="d8e3" streamable="yes" use-accumulators="position"/>
   <xsl:mode name="d8e3-entry" streamable="yes" use-accumulators="position"/>
   <xsl:template match="/" mode="d8e3-entry">
      <schxslt:pattern id="d8e3@{base-uri(.)}"/>
      <xsl:apply-templates mode="d8e3" select="."/>
   </xsl:template>
   <xsl:template match="book" priority="0" mode="d8e3-grounded">
      <xsl:param name="schxslt:rules" as="element(schxslt:rule)*"/>
      <xsl:choose>
         <xsl:when test="empty($schxslt:rules[@pattern = 'd8e3'][@context = generate-id(current())])">
            <schxslt:rule pattern="d8e3@{base-uri(.)}">
               <xsl:if test="not(exists(author))">
                  <svrl:failed-assert xmlns:mf="http://example.com/mf"
                                      xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
                                      location="{schxslt:location(.)}">
                     <xsl:attribute name="test">exists(author)</xsl:attribute>
                     <svrl:text>Book doesn't have author.</svrl:text>
                  </svrl:failed-assert>
               </xsl:if>
            </schxslt:rule>
         </xsl:when>
         <xsl:otherwise>
            <schxslt:rule pattern="d8e3@{base-uri(.)}">
               <xsl:comment xmlns:mf="http://example.com/mf" xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "book" shadowed by preceeding rule</xsl:comment>
               <xsl:message xmlns:mf="http://example.com/mf" xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "book" shadowed by preceeding rule</xsl:message>
               <svrl:suppressed-rule xmlns:mf="http://example.com/mf" xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
                  <xsl:attribute name="context">book</xsl:attribute>
               </svrl:suppressed-rule>
            </schxslt:rule>
         </xsl:otherwise>
      </xsl:choose>
      <xsl:next-match>
         <xsl:with-param name="schxslt:rules" as="element(schxslt:rule)*">
            <xsl:sequence select="$schxslt:rules"/>
            <schxslt:rule context="{generate-id()}" pattern="d8e3"/>
         </xsl:with-param>
      </xsl:next-match>
   </xsl:template>
   <xsl:template match="book" priority="0" mode="d8e3">
      <xsl:param name="schxslt:rules" as="element(schxslt:rule)*"/>
      <xsl:apply-templates select="copy-of()" mode="d8e3-grounded"/>
   </xsl:template>
   <xsl:function xmlns="http://www.w3.org/1999/XSL/TransformAlias"
                 xmlns:mf="http://example.com/mf"
                 xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
                 name="schxslt:location"
                 as="xs:string"
                 visibility="public"
                 streamability="inspection">
      <xsl:param name="node" as="node()"/>
      <xsl:sequence select="$node =&gt; mf:path()"/>
   </xsl:function>
</xsl:transform>

Does that allow to tell where the problem is caused? I can provide the import as well but as it uses several files I hope the above suffices to tell where the problem comes from.


Replies (2)

RE: ClassCastException: net.sf.saxon.expr.instruct.CopyOf cannot be cast to net.sf.saxon.expr.AxisExpression - Added by Martin Honnen about 4 years ago

I have now reduced the code to three files, the input sample books.xml, the main stylesheet single-pattern-burst-test-compiled-xslt30-streamable.xsl and one import position-accumulator.xsl so running e.g. java -jar 'C:\Program Files\Saxonica\SaxonEE10-2J\saxon-ee-10.2.jar' -t -s:.\books.xml -xsl:.\single-pattern-burst-test-compiled-xslt30-streamable.xsl produces the exception.

All three files are attached.

    (1-2/2)

    Please register to reply