Search code examples
functionxpathschematron

Check if each third value of text node is equal to eachother


I have the following XML snippet:

<..>
  <gml:posList srsDimension="3">
    10.0 10.0 0.0 10.0 15.0 0.0 13.0 15.0 0.0 13.0 10.0 0.0 10.0 10.0 
  </gml:posList>
</..>

Now I want to check in schematron that each third value of the list is equal to one another (in this case its 0.0)

I have been trying stuff with

fn:tokenize(descendant::gml:posList/text(),'\s+')

But now I still need to make sure I only get each third value and compare them with another..

Any ideas?


Solution

  • I think you can construct your Schematron assertion like this:

    fn:count(
      fn:distinct-values(fn:tokenize(gml:posList/fn:normalize-space(.), '\s+')
      [(position() mod 3) eq 0])) eq 1
    

    That gets every third value and asserts that all those values are the same.