Project

Profile

Help

Howto validate if values of elements are in sequence

Added by Haris Lihvoac over 5 years ago

In xml file

@ 1 2 3 @

I need xsd to validate if values of all elements are in sequence starting from 1.

I tried to use something like this at level but no success :( @ <xs:assert test="./preceding-sibling::*[1]/rowid/number()+1 = $value" saxon:message="Value of element 'rowid' must be in squence!" /> @

I tried to understand http://www.w3.org/TR/xmlschema11-1/#assertion-validation with special referring to "Note: It is a consequence of this construction that attempts to refer, in an assertion, to the siblings or ancestors of E, or to any part of the input document outside of E itself, will be unsuccessful. Such attempted references are not in themselves errors, but the data model instance used to evaluate them does not include any representation of any parts of the document outside of E, so they cannot be referred to."

While in XSL transformation this works: @<xsl:value-of select="preceding-sibling::*[1]/rowid/number()" />@

Therefore I wonder if this possible to use siblings in assertion at all?

Thx in advance for any help/advice.


Replies (2)

RE: Howto validate if values of elements are in sequence - Added by Michael Kay over 5 years ago

Can I assume that this question has nothing to do with Saxon-CE (since Saxon-CE does not support XSD validation)? In fact, can I assume that it has nothing to do with Saxon at all? (You might have done better posting on StackOverflow).

Any assertion that involves more than one sibling row element is considered to be an assertion about their common ancestor: the rows considered individually are valid, but their parent (the root element) is invalid. You want an assertion on the root element something like

test="every $r in row satisfies $r/rowid = count($r/preceding-sibling::*) + 1"

(Saxon's implementation recognizes assertions of the form "every $x ... satisfies" specially, and in the event of an error, tells you which $x fails to satisfy the assertion).

RE: Howto validate if values of elements are in sequence - Added by Haris Lihvoac over 5 years ago

I apologize for confusion of CE with EE :(

However I thank you for your kind reply.

Wish you all the best!

    (1-2/2)

    Please register to reply