0
votes

I am trying to write schematron rule to compare an attribute of a current sub-element (End @value) in a loop with next sub-elements attribute(Origin @value). I am not sure if i am doing the right thing so here is my attempt

Here is my attempt:

<sch:rule context="test">
    <sch:assert test="End/@value = following-sibling::test/Origin/@value " >Both the value are not Equal. </sch:assert>
</sch:rule>

This rule is working fine till the last element, the last element is expecting another element which is not present. the problem could be with "following-sibling" .

Here is XML file:

<tests>
<test x="-276.724" xEnd="-276.193">
    <Origin value="36.599"/>
    <End value="36.6"/>
</test>
<test x="-276.193" xEnd="-260.29">
    <Origin value="36.6"/>
    <End value="36.603"/>
</test>
<test x="-260.29" xEnd="-240.194">
    <Origin value="36.603"/>
    <End value="36.601"/>
</test>
<test x="-240.194" xEnd="-220.046">
    <Origin value="36.601"/>
    <End value="36.601"/>
</test>
<test x="-220.046" xEnd="-200.09">
    <Origin value="36.601"/>
    <End value="36.602"/>
</test>

Expected result: As current sub-element (End @value) = next sub-elements attribute(Origin @value), the Output should be success.

Actual result.

    <test x="-220.046" xEnd="-200.09">
    <Origin value="36.601"/>
    <End value="36.602"/>
</test>

foe this element i am getting assretion failure

1

1 Answers

0
votes

I assume that you are using the XSLT 2.0 binding.

If so, End/@value = following-sibling::test/Origin/@value is comparing the value attribute of the End child element with the value attribute of the Origin child element of every following sibling test element. That evaluates to true if any of the Origin/@value values match. That's probably not what you want.

The End and Origin elements are both children of the test element, which is the context for your XPath expressions. If you want to test the two child elements:

<sch:rule context="test">
  <sch:assert test="End/@value = Origin/@value"
  >Both the  value are not Equal. </sch:assert>
</sch:rule>

If you want to test the End/@value from the current test element with the Origin/@value from the following test element but not fail when there is no following test element:

<sch:rule context="test[exists(following-sibling::test[1])]">
  <sch:assert test="End/@value = following-sibling::test[1]/Origin/@value"
  >Both the  value are not Equal. </sch:assert>
</sch:rule>

The [1] limits the XPath to selecting just the first test.