Schematron problem

Questions about XML that are not covered by the other forums should go here.
m0ps
Posts: 3
Joined: Wed Sep 22, 2010 12:27 pm

Schematron problem

Post 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
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Schematron problem

Post 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
m0ps
Posts: 3
Joined: Wed Sep 22, 2010 12:27 pm

Re: Schematron problem

Post by m0ps »

wooohooo, thx! 3 hours because of a wrong number! :D thx very much!
Post Reply