You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 04:23:17