gpt4 book ai didi

xpath - XPATH删除元素串联中的多余空格

转载 作者:行者123 更新时间:2023-12-03 17:21:47 26 4
gpt4 key购买 nike

在XPATH中,我正在处理如下所示的源XML,在该XML中,我想用空格定界符将每个editor的子元素连接起来以创建全名,然后依次将结果全名用逗号连接:

<biblStruct type="book" xml:id="Biller_2011a">
<monogr>
<title>Inquisitors and Heretics in Thirteenth-Century Languedoc: Edition and Translation
of Toulouse Inquisition Depositions, 1273-1282</title>
<editor>
<forename>Peter</forename><surname>Biller</surname>
</editor>
<editor>
<forename>Caterina</forename><surname>Bruschi</surname>
</editor>
<editor>
<forename>Shelagh</forename><surname>Sneddon</surname>
</editor>
<imprint>
<pubPlace>
<settlement>Leiden</settlement>
<country>NL</country>
</pubPlace>
<publisher>Brill</publisher>
<date type="pub_date">2011</date>
</imprint>
</monogr>
</biblStruct>


当前,XPATH(在XQuery中)代码如下所示,使用XPATH map引入定界符:

let $bibref := $bib//tei:biblStruct[@xml:id="Biller_2011a"]
return <editors>{
(for $auth in $bibref//tei:editor
return normalize-space(string-join($auth//child::text()," ")))!(if (position() > 1) then ', ' else (), .)
}</editors>


但这会在逗号前后输出额外的空间:

<editors>Peter Biller ,  Caterina Bruschi ,  Shelagh Sneddon</editors>


相反,我想输出:

<editors>Peter Biller, Caterina Bruschi, Shelagh Sneddon</editors>  


提前致谢。

最佳答案

“我要在其中连接每个editor的子元素的位置”将转换为$auth/*而不是$auth//child::text()

for return!以及string-join的整体组合看起来有些奇怪,看来您只能使用string-join($bibref//tei:editor/string-join(*, ' '), ', ')

关于xpath - XPATH删除元素串联中的多余空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53997232/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com