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

假设您在XSD 1.1中有2个属性:“ 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)" />


但是它不起作用,当所有属性都不存在时,它会提供错误,因为它试图执行比较。

在与Test进行比较之前是否可以检查两个属性都存在?
能够测试以前的测试条件的东西将是非常有趣的。

任何帮助将不胜感激。

最佳答案

尝试:

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

关于xml - XSD断言取决于属性的存在,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24871868/

10-11 23:05
查看更多