Schematron中"xs:"是否为内置前缀?需用ns关联XMLSchema命名空间吗?
在Schematron中
xs:前缀的使用说明 xs:并不是Schematron的内置前缀,不能直接使用——你必须显式地通过命名空间声明或者sch:ns指令,将这个前缀关联到XMLSchema的标准命名空间 http://www.w3.org/2001/XMLSchema,之后才能在Schematron规则里用xs:引用XMLSchema的类型、函数或元素。
举个实际的例子,你可以在Schematron schema的根元素里直接声明命名空间:
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <sch:rule context="user-input"> <!-- 使用xs:string引用XMLSchema字符串类型 --> <sch:assert test="instance of xs:string">用户输入必须为字符串类型</sch:assert> </sch:rule> </sch:schema>
或者用sch:ns指令来关联前缀(适合需要集中管理命名空间的场景):
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron"> <sch:ns prefix="xs" uri="http://www.w3.org/2001/XMLSchema"/> <sch:rule context="user-input"> <sch:assert test="matches(., xs:token('\w+'))">输入格式不符合要求</sch:assert> </sch:rule> </sch:schema>
内容的提问来源于stack exchange,提问作者Gerben Abbink
相关产品推荐
相关产品推荐

