Xml 通过模式XSD检查属性值

Xml 通过模式XSD检查属性值,xml,xsd,Xml,Xsd,我需要检查“book”(root)元素的属性值“id” 如果“id”值以三个零结尾(id=“******-000”),则另一个属性“book type”应为“book”,否则应为“chapter” 以下是我的xml格式: <book id="201019894-000" book-type="book" xsi:noNamespaceSchemaLocation="schema.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instanc

我需要检查“book”(root)元素的属性值“id”

如果“id”值以三个零结尾(id=“******-000”),则另一个属性“book type”应为“book”,否则应为“chapter”

以下是我的xml格式:

<book id="201019894-000" book-type="book" xsi:noNamespaceSchemaLocation="schema.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<book-meta>
<title-group>...

...
是否有可能在模式(xsd)中检查上述条件

请引导我


谢谢

在XSD1.0中无法完成

在XSD 1.1中,您可以通过如下断言来实现

<xs:assert test="if (ends-with(@id, '-000') then @book-type='book' else @book-type='chapter'"/>