Sequential attribute values.
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 42
- Joined: Sun Jul 15, 2012 12:26 pm
- Location: London
Sequential attribute values.
Hello,
Is there an easy way to verify that an attribute's value is sequential from a series of elements and if not what ones are missing?
Assuming that the values started at 1 I could use @id = position() but that doesn't answer the what's missing question.
I would appreciate your thoughts on this.
--
William
Is there an easy way to verify that an attribute's value is sequential from a series of elements and if not what ones are missing?
Assuming that the values started at 1 I could use @id = position() but that doesn't answer the what's missing question.
I would appreciate your thoughts on this.
--
William
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Sequential attribute values.
Hi,
For XSLT, if the attribute's value range is reasonable, you can simply iterate on each value of the attribute and check if it exists.
e.g.
XML (not ordered): XSLT (iterates between 1 and the maximum value of the id attribute):
This will just issue messages for the missing id values:
Regards,
Adrian
For XSLT, if the attribute's value range is reasonable, you can simply iterate on each value of the attribute and check if it exists.
e.g.
XML (not ordered):
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item id="3"></item>
<item id="5"></item>
<item id="1"></item>
<item id="7"></item>
<item id="10"></item>
</root>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.0">
<xsl:template match="/">
<xsl:variable name="root" select="."/>
<xsl:message select="'enter'"/>
<xsl:for-each select="1 to xs:integer(max(//item/@id))">
<xsl:variable name="i" select="."/>
<xsl:if test="not($root//item[@id = $i])">
<xsl:message select="concat('not found: ', $i)"/>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Code: Select all
[Saxon-PE] not found: 2
[Saxon-PE] not found: 4
[Saxon-PE] not found: 6
[Saxon-PE] not found: 8
[Saxon-PE] not found: 9
Adrian
Adrian Buza
<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
Return to “General XML Questions”
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