Limit attribute values ​​based on attribute

I want to limit the type of an element based on an attribute value, for example:

<Data type = "decimal"> 44.00 </ data>

<Data type = "date"> 2008-02-01 </ data>

Is it possible to define a circuit that does this?

+1
source share
1 answer

It’s well known that XML Schema cannot do this,

checking an element based on another element is considered ambiguous, so this is not possible. But if you want, you can check the data type of both types, ignoring conditional validation, something like this:

Define a new data type with a custom name and copy the pattern below.

<xs:simpleType name="new_type"> <xs:restriction base="xs:string"> <xs:pattern value="(([0-9]+)[.]([0-9]+))|(([0][1-9]|[1][0-2])/([0][1-9]|[1-2][0-9]|[3][0-1])/[1-2][0-9][0-9][0-9])"/> </xs:restriction> </xs:simpleType> 

This will accept data like decimal or date, but you cannot check it with attribute values,

An alternative solution is to use Schematron, but you will not get such a convenient and user-friendly tool for this, as you will get with XSD and XSLT.

0
source

Source: https://habr.com/ru/post/1305141/


All Articles