XSD assertions conditioned by the existence of attributes

左心房为你撑大大i 提交于 2019-12-13 02:27:38

问题


I am looking for a solution to the following case:

Suppose that you have 2 attributes in an XSD 1.1: "startDate" and "endDate". Suppose also that those are optional and you need to check if those are present or not. The following xsd shall work:

<complexType name="exampleType">
    <attribute name="startDate" type="date" use="optional" />
    <attribute name="endDate" type="date" use="optional" />
    <assert test="(exists(@startDate) = exists(@endDate))"/>
</complexType>

What I would need is a way check that startDate is less or equal to endDate only in case both of them are provided. I have tried with those asserts:

<assert test="(exists(@startDate) = exists(@endDate)) and (@startDate le @endDate)"/>

<assert test="exists(@startDate) = (@startDate le @endDate)" /> 

But it does not work, when none of the attributes exist it provides a false because tries to execute the comparison.

Is it possible to check that both attributes exist before apply a comparison with Test? It would be very interesting to have the possibility to test something conditioned by a previous test.

Any help would be very appreciated.


回答1:


Try:

<assert test="not(@endDate lt @startDate)"/>


来源:https://stackoverflow.com/questions/24871868/xsd-assertions-conditioned-by-the-existence-of-attributes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!