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

如何修改XSD的xs:assert以校验同类型元素值不重复?

修改XSD断言实现多子元素属性唯一性校验

针对connected_condition复杂类型的多子元素属性校验需求,将原断言替换为以下代码:

<xs:assert test="not(@annotation = annotation/@annotation) and count(distinct-values(annotation/@annotation)) = count(annotation/@annotation)"/>

断言逻辑说明

  • 父元素与子元素属性不重复:not(@annotation = annotation/@annotation)
    XPath中当右侧为节点集时,=会判断左侧值是否匹配节点集中任意一个值,not()取反后确保父元素的annotation属性值与所有annotation子元素的对应属性值都无重复。
  • 子元素间属性互不重复:count(distinct-values(annotation/@annotation)) = count(annotation/@annotation)
    通过distinct-values()去重后,比较去重后的属性值数量与子元素总数,相等则说明所有子元素的annotation属性值没有重复。

注意事项

  • 若父元素的属性名不是annotation,请将代码中的@annotation替换为实际的父元素属性名称。
  • 该断言依赖XSD 1.1支持的XPath 2.0特性,与你使用的XML 1.1环境兼容。

内容的提问来源于stack exchange,提问作者Daniel Janz

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 21:34:58