phax / ph-schematron

Java Schematron library that supports XSLT and native application
Apache License 2.0
110 stars 36 forks source link

Variable defined as a for expression causes a warning #173

Closed bertrand-lorentz closed 1 month ago

bertrand-lorentz commented 1 month ago

Following the changes in issue #170, I've noticed that a variable defined with a for expression causes a warning.

For example, with the same xml used in the unit test for issue #170:

<let name="forVar" value="for $i in //owner[@id = 'o2']/@id return //car[@owner = $i]/@id"/>

<assert role="ERROR" test="$forVar = //car/@id">error message</assert>

The warning is: WARN com.helger.schematron.pure.xpath.XPathEvaluationHelper$SaxonEvaluator - Unknown Saxon expression type: net.sf.saxon.expr.ForExpression

The schematron still works, and the assert does not cause any failure (as expected), because after XPathEvaluationHelper.evaluateWithTypeAutodetect fails and produces the warning, then XPathEvaluationHelper.evaluateAsNodeList works and returns a node list.

So this is not really a problem, but I thought it might be useful to report it anyways, for the completeness of the type autodetection magic. 😃

phax commented 1 month ago

Thanks a lot - integrated and will be part of the next 8.0.2 release :)

bertrand-lorentz commented 1 month ago

The change in the commit doesn't look right: I think ((ForExpression) expr).getItemType () returns the type of a single item returned by the for expression, but in general a for expression returns a sequence of such items.

Because of this, in the unit test, $forVar evaluates to "c2". The correct value would be the list ("c2", "c3"). The test in the assert is not specific enough to catch this (my bad).

phax commented 1 month ago

Okay, so you are proposing, that this will be mapped to the "Nodeset" type than???

bertrand-lorentz commented 1 month ago

Based on what I've seen, mapping ForExpression to NODESET might indeed be the best approach: it seems to work regardless of the type of the items in the sequence returned by the expression: node, string, etc.

phax commented 1 month ago

So be it :)