Schematron & Counting Total # of Attributes
Posted: Tue Dec 17, 2013 5:02 am
Hi all-
New to schematron, so thank you for your help in advance!
I have built a pattern that is suppose to count the number of attributes that are equal to a certain number and 'assert' that the total number of attributes equal to that value is equal to 1.
My rule is not working and I don't understand why. The rule is to enforce that only a single tree node is allowed in my XML document. I thought it was working with the XML document listed below, but when I set the ParentID=0 on a second Property element, the assertion does not send back the error message.
I don't have control of the XML schema, so I can't change its format.
This is the rule in my schematron file:
This is a snipit of my XML file:
New to schematron, so thank you for your help in advance!
I have built a pattern that is suppose to count the number of attributes that are equal to a certain number and 'assert' that the total number of attributes equal to that value is equal to 1.
My rule is not working and I don't understand why. The rule is to enforce that only a single tree node is allowed in my XML document. I thought it was working with the XML document listed below, but when I set the ParentID=0 on a second Property element, the assertion does not send back the error message.
I don't have control of the XML schema, so I can't change its format.
This is the rule in my schematron file:
Code: Select all
<sch:pattern id="Check_Root">
<sch:rule context="//TreeData/Property/Property[@Name='ParentID' and @Value=0]">
<sch:assert test="count(@Value=0]) = 1">
Only a single root is allowed in the tree. Check source XML document.
</sch:assert>
</sch:rule>
</sch:pattern>
Code: Select all
<TreeData Name="Organization">
<Property Name="Unit" Value="100">
<Property Name="Name" Value="Root"/>
<Property Name="ParentID" Value="0"/>
</Property>
<Property Name="Unit" Value="200">
<Property Name="Name" Value="File_Folder_01"/>
<Property Name="ParentURN" Value="100"/>
</Property>
<Property Name="Unit" Value="300">
<Property Name="Name" Value="File_Folder_02"/>
<Property Name="ParentURN" Value="200"/>
</Property>
<Property Name="Unit" Value="400">
<Property Name="Name" Value="File_Folder_03"/>
<Property Name="ParentURN" Value="300"/>
</Property>
</TreeData>