使用xquery分割一个范围



我有一个如下的xml

<content>
<customer id="250">
<assert  PropertyType="product" PropertyValues="0009~0013" DisplayClass="confirmed"/>
<assert  PropertyType="product" PropertyValues="0001" DisplayClass="confirmed"/>
</customer>
<customer id="100">
<assert  PropertyType="product" PropertyValues="0008|0010~0012" DisplayClass="confirmed"/>
</customer>
<customer id="6000">
<assert  PropertyType="product" PropertyValues="0013|0036|0042|0047" DisplayClass="confirmed"/>
</customer>
</content>

我想要得到每个PropertyValues属性,这是在断言标签,应该搜索0011值,并返回一个布尔值
我有不同的操作符,如~(范围)和|(分隔符),这实际上意味着
PropertyValues="0009~0013"——>0009到0013——我有序列0009 0010 0011 0013
PropertyValues= 0008|0010~0012"——比;我有0008 0010 0011 0012
PropertyValues= 0013|0036|0042|0047"——比;我有0013 0036 0042 0047

我如何使用Xquery执行此操作
任何建议/想法将非常感激,谢谢!

您可以使用tokenize函数来拆分内容,您可以使用范围操作符to来"翻译"。你的范围语法与~成一个序列,最后你只需要检查结果序列是否包含你的值:

//@PropertyValues 
! 
(. || ': ' || (((tokenize(., '|') ! (let $tokens := tokenize(., '~')!xs:integer(.) return $tokens[1] to $tokens[2])) ! format-integer(., '0001')) = '0011'))

at https://xqueryfiddle.liberty-development.net/94hwpi2输出

0009~0013: true
0001: false
0008|0010~0012: true
0013|0036|0042|0047: false

最新更新