saxon:evaluate fails on an XPath string that contains a variable reference

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

saxon:evaluate fails on an XPath string that contains a variable reference

Costello, Roger L.
Hi Michael,

I discovered that Saxon throws a RuntimeException when using saxon:evaluate on an XPath string that contains a variable reference.

This xpath-expression:

        $schema//*[@type eq 'xs:anySimpleType']

generates this error:

java.lang.RuntimeException: Internal error evaluating template  at line 16 in module foo.xsl
        at net.sf.saxon.expr.instruct.Template.applyLeavingTail(Template.java:353)
        at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:1155)
        at net.sf.saxon.trans.TextOnlyCopyRuleSet.process(TextOnlyCopyRuleSet.java:65)
        at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:1131)
        at net.sf.saxon.Controller.transformDocument(Controller.java:2106)
        at net.sf.saxon.Controller.transform(Controller.java:1705)
        at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:547)
        at net.sf.saxon.Transform.processFile(Transform.java:1056)
        at net.sf.saxon.Transform.doTransform(Transform.java:659)
        at net.sf.saxon.Transform.main(Transform.java:80)
Caused by: java.lang.NullPointerException
        at net.sf.saxon.expr.VariableReference.iterate(VariableReference.java:449)
        at net.sf.saxon.expr.ItemChecker.iterate(ItemChecker.java:185)
        at net.sf.saxon.expr.SlashExpression.iterate(SlashExpression.java:850)
        at net.sf.saxon.expr.sort.DocumentSorter.iterate(DocumentSorter.java:172)
        at com.saxonica.functions.extfn.Evaluate$EvaluateCall.call(Evaluate.java:292)
        at net.sf.saxon.functions.IntegratedFunctionCall.call(IntegratedFunctionCall.java:327)
        at EE__Slash_xs_schema_91510147134.process(foo.xsl:67)
        at com.saxonica.ee.bytecode.CompiledExpression.process(CompiledExpression.java:66)
        at net.sf.saxon.expr.instruct.Template.applyLeavingTail(Template.java:342)
        ... 9 more
Fatal error during transformation: java.lang.RuntimeException: Internal error evaluating template  at line 16 in module foo.xsl

------------------------------------------------------------------------------
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: saxon:evaluate fails on an XPath string that contains a variable reference

Michael Kay

> On 13 Jun 2015, at 17:19, Costello, Roger L. <[hidden email]> wrote:
>
> Hi Michael,
>
> I discovered that Saxon throws a RuntimeException when using saxon:evaluate on an XPath string that contains a variable reference.
>
> This xpath-expression:
>
> $schema//*[@type eq 'xs:anySimpleType']
>
> generates this error:
>

Yes, that is how it is specified.

http://www.saxonica.com/documentation/#!functions/saxon/evaluate

<quote>The static context for the expression includes all the in-scope namespaces, types, and functions from the calling stylesheet or query. It does not include any variables from the calling environment.</quote>

The reason for this is that it would become impossible to optimize variables, e.g. eliminating a variable that is not used, because references from dynamically evaluated expressions cannot be detected by the compiler.

You can bind parameters though:

saxon:evaluate(“$p//*[@type eq 'xs:anySimpleType’]”, $schema)

The XSLT 3.0 xsl:evaluate instruction similarly does not allow the expression to access variables defined in the containing stylesheet, and it provides a more flexible solution for passing parameters.

Michael Kay
Saxonica




------------------------------------------------------------------------------
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help