XQuery在定界符之间获取字符串
我有(tei)xml,有像 < ref target =“#a1”/>
,但< ref target =“#a1#b2#c3”/>
我需要编写Xquery代码以将每个#
-target转换为链接;如果我只有一个target =“#a1”
,那么这没问题,然后我使用substring-fer($ node/@target,'#')
并寻找XML-ID
与子字符串相同,但是如果子字符串比所需的时间长,当然我会遇到问题,则无匹配。 有没有一种方法可以在#
和Space
或#
和之间选择substring? (我是Xquery的新手,很抱歉,如果我问一些非常明显的事情,但找不到经济解决方案)
I have (TEI)XML with bits like<ref target="#a1"/>
but also <ref target="#a1 #b2 #c3"/>
I need to write the xquery code to transform each #
-target to a link; this is no problem if I have just one target="#a1"
, then I use substring-after($node/@target, '#')
and look for xml-id
s that are the same as the substring, but then of course I get problems if the substring is longer than needed, no match is possible.
Is there a way to select the substring between #
and space
or #
and "
?
(I am very new to xquery so sorry if I am asking something very obvious, but I could not find an economic solution)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以
tokenize()
可选空间的属性值\ s
和#
带有此Regex\ s?#
,然后用谓词过滤出一个空项目使用normalize-space()
或测试字符串长度字符串长度(。)gt 0
:或者您可以通过Space
\ S
或空间和#\ s#
,然后translate()
剩下的任何#
nothens:读取空间分离
ref/@target
属性值作为序列的另一种方法是将它们读为xs:nmtokens
(它们是空间分离值),然后您只需要担心从每个值中删除#
You could
tokenize()
the attribute value by an optional space\s
and#
with this regex\s?#
and then filter out an empty item with a predicate usingnormalize-space()
or testing the string lengthstring-length(.) gt 0
:or you could tokenize by space
\s
or space and #\s#
, thentranslate()
any remaining#
into nothing:Another way to read the space separated
ref/@target
attribute values as a sequence is to read them asxs:NMTOKENS
(which are space separated values), and then you just need to worry about removing the#
from each value: