Page 1 of 1

Schematron problem

Posted: Mon Apr 11, 2011 12:53 pm
by m0ps
heyho,
have a XML like:

Code: Select all


<DNgV>
<DeviceTest name="test1" type="Test" spec="harddisc">
<parent name="ptest1" type="Test" spec="pci">
<parent name="pptest1" type="Test" spec="pci">

...
I use Schematron Validation and want to test, if DeviceTest-name attribute is unique. Means no other DeviceTest-name and no other parent-name should have the same string.

In schematron i wrote following:

Code: Select all


        <iso:pattern id="uniqueness.DInvDeviceTest">
<iso:rule context="//dnv:DeviceTest/@name">
<iso:assert test="count(//dnv:DeviceTest/@name[. = current()]) = 1">
Attribute is not unique in 'DeviceTest'
</iso:assert>
<iso:assert test="count(//dnv:parent/@name[. = current()]) = 1">
Attribute is not unique 'parent/DeviceTest'
</iso:assert>
</iso:rule>
</iso:pattern>
This Schematron works for the test if another DeviceTest has the same name. But i can't figure out why the second test allways leads to an error. what's wrong here?

Greetz
m0ps

Re: Schematron problem

Posted: Mon Apr 11, 2011 4:22 pm
by sorin_ristache
Hello,
m0ps wrote:I use Schematron Validation and want to test, if DeviceTest-name attribute is unique. Means no other DeviceTest-name and no other parent-name should have the same string.
For a unique DeviceTest/@name value you need to test in the second assert that there is no parent element with the same name attribute as the one matched by the context attribute:

Code: Select all

      <assert test="count(//dnv:parent/@name[. = current()]) = 0">
Attribute is not unique 'parent/DeviceTest'
</assert>
Regards,
Sorin

Re: Schematron problem

Posted: Mon Apr 11, 2011 4:28 pm
by m0ps
wooohooo, thx! 3 hours because of a wrong number! :D thx very much!