Check for duplicates attribute value
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 24
- Joined: Thu Jan 07, 2021 10:44 am
Check for duplicates attribute value
Post by DanOvergaard »
Hi,
Is there a validation in Xslt 2.0 that can test for duplicates in an attribute
If would like to catch that there a two “DK” languageID’s in the XML below
<cac:notes>
<cbc:note languagesID=“DK”>test</cbc:note>
<cbc:note languagesID=“SE”>test</cbc:note>
<cbc:note languagesID=“UK>test</cbc:note>
<cbc:note languagesID=“DK”>test</cbc:note>
</cac:notes>
Regards,
Dan
Is there a validation in Xslt 2.0 that can test for duplicates in an attribute
If would like to catch that there a two “DK” languageID’s in the XML below
<cac:notes>
<cbc:note languagesID=“DK”>test</cbc:note>
<cbc:note languagesID=“SE”>test</cbc:note>
<cbc:note languagesID=“UK>test</cbc:note>
<cbc:note languagesID=“DK”>test</cbc:note>
</cac:notes>
Regards,
Dan
-
- Posts: 102
- Joined: Tue Aug 19, 2014 12:04 pm
Re: Check for duplicates attribute value
Post by Martin Honnen »
Validation is usually done with a schema language like XSD or Schematron (which is often implemented with XSLT under the hood).
So yes, you can can of course define the languagesID attribute with an xs:ID type and you would get a validation error for your sample.
In XSLT you can use a key or use for-each-group based on the attribute value and then you could check whether the group contains more than one item. Neither keys nor for-each-group are in any way restricted on attributes but can of course be used for them like for other nodes or values.
So yes, you can can of course define the languagesID attribute with an xs:ID type and you would get a validation error for your sample.
In XSLT you can use a key or use for-each-group based on the attribute value and then you could check whether the group contains more than one item. Neither keys nor for-each-group are in any way restricted on attributes but can of course be used for them like for other nodes or values.
-
- Posts: 24
- Joined: Thu Jan 07, 2021 10:44 am
Re: Check for duplicates attribute value
Post by DanOvergaard »
Hi Martin,
Thanks for your feedback - I used "for-each-group" and solved the problem
It's a "sch:schema" that is the source that builds the XSLT validation, but I couldn't find a solution to do this test - Actually I find that more complex validations is hard to solved in a sch:schema, but it might be my lack of knowledge
To solve the problem original in XSL ver. 1.0 the test below was used but it's not allowed in XSL 2.0
<sch:report test="local-name(following-sibling::*) = local-name(current()) and following-sibling::*/@languageID = self::*/@languageID">Error message</sch:report>
Regards,
Dan
Thanks for your feedback - I used "for-each-group" and solved the problem

It's a "sch:schema" that is the source that builds the XSLT validation, but I couldn't find a solution to do this test - Actually I find that more complex validations is hard to solved in a sch:schema, but it might be my lack of knowledge
To solve the problem original in XSL ver. 1.0 the test below was used but it's not allowed in XSL 2.0
<sch:report test="local-name(following-sibling::*) = local-name(current()) and following-sibling::*/@languageID = self::*/@languageID">Error message</sch:report>
Regards,
Dan
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