Schematron & Check for Unique attribute
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 4
- Joined: Tue Dec 17, 2013 4:39 am
Schematron & Check for Unique attribute
...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>
-
- Posts: 4
- Joined: Tue Dec 17, 2013 4:39 am
Re: Schematron & Check for Unique attribute
Just came up with a working solution...
Code: Select all
<xsl:key name="getAllRoles" match="//DataSets/DataSet[@Name='Folders']/Property/Property[@Name='Role']" use="@Value"/>
<sch:pattern id="CheckOrganization_UniqueRole">
<sch:rule context="//DataSets/DataSet[@Name='Folders']/Property">
<sch:assert test="count(key('getAllRoles',Property/@Value)) = 1" role="warning">
Warning: Roles for Folders should be unique.
</sch:assert>
</sch:rule>
</sch:pattern>
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