Schematron & Check for Unique attribute
Posted: Wed Dec 18, 2013 4:47 am
...Still new to schematron... thank you in advance for your help...
I have a source XML document where I need to assert that an attribute is unique in a set of elements. I built a rule to enforce this, but its not working. I searched online and tried to follow some examples I found, but still no dice...
This is my source XML:
This is my rule:
I have a source XML document where I need to assert that an attribute is unique in a set of elements. I built a rule to enforce this, but its not working. I searched online and tried to follow some examples I found, but still no dice...
This is my source XML:
Code: Select all
<TreeView>
<DataSets>
<DataSet Name="Folders">
<Property Name="Folder" Value="101">
<Property Name="Name" Value="Cars"/>
<Property Name="Role" Value="a"/>
</Property>
<Property Name="Folder" Value="102">
<Property Name="Name" Value="Boats"/>
<Property Name="Role" Value="b"/>
</Property>
<Property Name="Folder" Value="103">
<Property Name="Name" Value="Bikes"/>
<Property Name="Role" Value="c"/>
</Property>
<Property Name="Folder" Value="104">
<Property Name="Name" Value="Trains"/>
<Property Name="Role" Value="d"/>
</Property>
<DataSet>
</DataSets>
</TreeView>
This is my rule:
Code: Select all
<sch:pattern id="Check_Unique_Roles">
<sch:rule context="//DataSets/DataSet[@Name='Folders']">
<sch:assert test=" count(Property/Property[@Name='Role']) =
count(Property/Property[@Name='Role' and not(@Value=preceding-sibling/Property[@Name='Role']/@Value)])">
Roles for all Folders must be unique.
</sch:assert>
</sch:rule>
</sch:pattern>