Schematron & Counting Total # of Attributes
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 4
- Joined: Tue Dec 17, 2013 4:39 am
Schematron & Counting Total # of Attributes
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>
-
- Posts: 404
- Joined: Thu Aug 21, 2003 11:36 am
- Location: Craiova
- Contact:
Re: Schematron & Counting Total # of Attributes
Post by radu_pisoi »
Hello,
I think that the problem with your Schematron rule is the context in which the assertion is executed. This context is establish by the 'context' attribute from the rule element. So, in your case, for each Property element with @Name='ParentID' and @Value=0 you check (assert) that it has a single attribute @Value = 1.
I think that the next rule is more appropriate for your case:
In this case, we assert that there should be only a Property element with 'Name' and 'Value' attributes equals with 'ParentID' and '0' respectively. This assertion is performed in the context of the 'TreeData' element.
I hope this helps.
I think that the problem with your Schematron rule is the context in which the assertion is executed. This context is establish by the 'context' attribute from the rule element. So, in your case, for each Property element with @Name='ParentID' and @Value=0 you check (assert) that it has a single attribute @Value = 1.
I think that the next rule is more appropriate for your case:
Code: Select all
<sch:rule context="TreeData">
<sch:assert test="count(//Property[@Name='ParentID'][@Value=0]) = 1">
Only a single root is allowed in the tree. Check source XML document.
</sch:assert>
</sch:rule>
I hope this helps.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service