Schematron - Counting number of elements+attributes
Posted: Thu Aug 03, 2017 1:57 pm
Hi,
I have a strange problem in schematron - I need to create a role that an element with certain attribute value should occur in the XML exactly once. I created the following rule, but it doesn't show an error when the number of elements with 'en' attributes value is more than 1. However, if I change the constrain to e.g. 3, then it does show en error when there are only 2 of them. What am I doing wrong?
My rule:
This doesn't work either:
This XML instance should be incorrect - the name in one language should appear only once:
Thanks in advance for any help,
Ewa
I have a strange problem in schematron - I need to create a role that an element with certain attribute value should occur in the XML exactly once. I created the following rule, but it doesn't show an error when the number of elements with 'en' attributes value is more than 1. However, if I change the constrain to e.g. 3, then it does show en error when there are only 2 of them. What am I doing wrong?
My rule:
Code: Select all
<sch:pattern>
<sch:rule context="//description/functionalName/@languageCode">
<sch:assert test="count(.='en') = 1">The value of Type must be set to a valid GS1 document name</sch:assert>
</sch:rule>
</sch:pattern>
This doesn't work either:
Code: Select all
<sch:pattern>
<sch:rule context="//description">
<sch:assert test="count(functionalName/@languageCode='en') = 1">The value of Type must be set to a valid GS1 document name</sch:assert>
</sch:rule>
</sch:pattern>
Code: Select all
<description>
<functionalName languageCode='sv'/>
<functionalName languageCode='sv'/>
</description>
Thanks in advance for any help,
Ewa