XSD 1.1:将元素的使用限制为具有特定子字符串的另一个属性
XSD 1.1: Restrict use of an element to another attribute having a certain substring
对于另一个纸牌游戏,我应该设计一个元素,该元素仅在较早位置的属性具有任何值时才使用,该元素包含子字符串“Count”,如本例所示:
<card>
<type condition="numberCount" until="3">Draw</type>
<text>Draw one card for any new card on the field with a value not being 2 in the next 3 upcoming rounds.</text>
<count>-2</count>
</card>
我的问题是:如何根据元素“type”中的属性“condition”使用元素“count”,元素“type”的值中包含单词“Count”?我已经尝试使用以下断言来解决它,但它似乎有一个错误的表达式(至少它没有编译):<xs:assert test="if (type/@condition contains('Count')) then (count) else not(count)"/>
那么如何在 xml 方案中表达以下 if 语句:
if (type.condition.contains('Count') then required(count) else don't use(count))
您可以测试 type/@condition
值是否在谓词中包含单词 Count
,然后如果包含,则 count
元素是否存在,否则 return true()
.
<xs:assert test="if (type/@condition[contains(., 'Count')])
then exists(count)
else not(count)"/>
对于另一个纸牌游戏,我应该设计一个元素,该元素仅在较早位置的属性具有任何值时才使用,该元素包含子字符串“Count”,如本例所示:
<card>
<type condition="numberCount" until="3">Draw</type>
<text>Draw one card for any new card on the field with a value not being 2 in the next 3 upcoming rounds.</text>
<count>-2</count>
</card>
我的问题是:如何根据元素“type”中的属性“condition”使用元素“count”,元素“type”的值中包含单词“Count”?我已经尝试使用以下断言来解决它,但它似乎有一个错误的表达式(至少它没有编译):<xs:assert test="if (type/@condition contains('Count')) then (count) else not(count)"/>
那么如何在 xml 方案中表达以下 if 语句:
if (type.condition.contains('Count') then required(count) else don't use(count))
您可以测试 type/@condition
值是否在谓词中包含单词 Count
,然后如果包含,则 count
元素是否存在,否则 return true()
.
<xs:assert test="if (type/@condition[contains(., 'Count')])
then exists(count)
else not(count)"/>