[英]Schematron validating multiple elements
假设我有一个XML文档定义:
<people>
<person>
<city>London</city>
</person>
<person>
<city>Paris</city>
</person>
</people>
我想要一个负责检查每个人是否居住在伦敦的schematron。
我试过了:
<sch:rule context="people">
<sch:assert test="person/city = 'London'">Everybody must live in London!</sch:assert>
</sch:rule>
但是,只要有一个人居住在伦敦,这将返回true。 有没有办法告诉schematron对与XPathcondition人员/城市匹配的每个元素进行测试?
怎么样“没有人可以住在伦敦以外”:
<sch:rule context="people">
<sch:assert test="not(person[city != 'London'])">Everybody must live in London!</sch:assert>
</sch:rule>
这有许多不同的解决方案。 解决方案示例1,报告是否有人不在伦敦居住:
<sch:rule context="people">
<sch:report test="person/city != 'London'">Everybody must live in London!</sch:report>
</sch:rule>
示例解决方案2断言每个人都必须住在伦敦,请注意,这将每个不住在伦敦的人都报告为错误,而不是仅报告节点people
。
<sch:rule context="people/person">
<sch:assert test="city = 'London'">This person should be living in london</sch:assert>
</sch:rule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.