views:

22

answers:

1

Hi, I'm trying to write some Schematron rules and one of them is supposed to check, if elements are unique in the scope of parent element. So I have an example xml structure:

<abc>
  <elem id="qw0">
    <a>1</a>
    <a>2</a>
    <a>3</a>
  </elem>
  <elem id="qw1">
    <a>1</a>
    <a>2</a>
    <a>3</a>
    <a>3</a>
  </elem>
</abc>

My rule should check if each of the element's "a" elements is unique. In this specific example, for elem with id="qw1" there are two elements "a" with value "3". This should not be allowed.

So far I've come to this kind of rule:

<iso:pattern id="doc.abc">
  <iso:title>checking ABC</iso:title>
  <iso:rule context="elem">
    <iso:assert test="count(a[. = current()]) = 1">TACs should be unique.</iso:assert>
  </iso:rule>
</iso:pattern>

But this does not work, as it kind of looks through the whole document, not just the direct children of elem.

A: 

I found out that this may be solved with the following rule:

<iso:pattern id="doc.abc">
  <iso:title>checking ABC</iso:title>
  <iso:rule context="a">
    <iso:assert test="count(parent::node()/a[. = current()) = 1">TACs should be unique.</iso:assert>
  </iso:rule>
</iso:pattern>

But this fires up the rule for every a element.

It would be more elegant to fire it for every elem, no a.

Marcin Cylke