XSD断言取决于属性的存在 [英] XSD assertions conditioned by the existence of attributes

查看:112
本文介绍了XSD断言取决于属性的存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am looking for a solution to the following case:

假设XSD 1.1中有2个属性:"startDate"和"endDate". 还要假设这些是可选的,并且您需要检查这些是否存在.以下xsd应该可以工作:

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>

我需要的是一种仅在提供了两个条件的情况下,检查startDate小于或等于endDate的方法.我已经尝试过这些断言了:

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.

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

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.

任何帮助将不胜感激.

推荐答案

尝试:

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

这篇关于XSD断言取决于属性的存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆