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

时间:2019-01-01 16:49:12

标签: xpath

在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>  

谢谢。

1 个答案:

答案 0 :(得分:2)

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

某种程度上,!string-joinstring-join($bibref//tei:editor/string-join(*, ' '), ', ')的整体组合看起来很奇怪,看来您只能使用{{1}}。