phax / ph-schematron

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

Variables are not evaluated in the order they are declared #177

Closed bertrand-lorentz closed 3 weeks ago

bertrand-lorentz commented 1 month ago

With ph-schematron-pure 8.0.2, the following schematron will always cause a failed assert:

<let name="a" value="1"/>
<let name="a-plus-one" value="$a + 1"/>
<assert role="ERROR" test="$a-plus-one = 2">error message</assert>

I would expect the test to be always true.

After some debugging, it seems the declaration of a-plus-one is evaluated before the declaration of a. So a-plus-one will then be equal to 1.

The current behavior is probably because the variables are stored in a sorted Map: https://github.com/phax/ph-schematron/blob/master/ph-schematron-pure/src/main/java/com/helger/schematron/pure/binding/xpath/PSXPathVariables.java#L49

I guess using a Map that preserves insertion order would correct this.

phax commented 3 weeks ago

Part of the 8.0.3 release