Reputation: 406
I want to define an XSD which has a sequence of elements each representing a comma seperated list of values, with some restrictions. The element definition looks in principle like this:
<xs:element name="line">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="-?[0-9]*.[0-9]{1,2}(,-?[0-9]*.[0-9]{1,2})*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
This works fine, beside one issue that the generic quantifier *
will allow for undefined number of elements.
I have in another element of the xml tree an integer that specifies how many entries are needed.
I would like to use an <xs:assert test="..."/>
statement at the top level of my XSD to have a similar functionality like the <xs:pattern value="-?[0-9]*.[0-9]{1,2}(,-?[0-9]*.[0-9]{1,2})*"/>
but with the last asterisk replaced by that number stored in the other element.
I succesfully have similar tests included to verify that IDs of element sequences match provided counts, but can't figure out how to creat such a regexp test with dynamically defined pattern value.
Upvotes: 0
Views: 27
Reputation: 406
This can be achieved with the help of xs:assert
, fn:matches
and concat.
The assertion at a level that can reach all needed elements as children looks like the following.
<xs:assert test='every $line in Values/Line satisfies fn:matches($line, concat("^-?[0-9]*\.[0-9]{1,2}(,-?[0-9]*\.[0-9]{1,2}){",xs:string(Count - 1),"}$"))'/>
Upvotes: 0