Xml 以属性的存在为条件的XSD断言

Xml 以属性的存在为条件的XSD断言,xml,testing,xsd,assert,Xml,Testing,Xsd,Assert,我正在寻找以下情况的解决方案: 假设XSD1.1中有两个属性:“startDate”和“endDate”。 假设这些都是可选的,您需要检查它们是否存在。以下xsd应起作用: <complexType name="exampleType"> <attribute name="startDate" type="date" use="optional" /> <attribute name="endDate" type="date" use="option

我正在寻找以下情况的解决方案:

假设XSD1.1中有两个属性:“startDate”和“endDate”。 假设这些都是可选的,您需要检查它们是否存在。以下xsd应起作用:

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

我需要的是一种方式检查startDate是否小于或等于endDate,只有在同时提供这两种情况下才可以。我尝试过这些断言:

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

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

但它不起作用,当所有属性都不存在时,它会提供一个false,因为它试图执行比较

在应用与测试的比较之前,是否可以检查这两个属性是否存在? 如果有可能在之前的测试条件下测试某些东西,那将是非常有趣的

非常感谢您的帮助。

请尝试:

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

解决问题的备选方案: