jbrehr
jbrehr

Reputation: 815

XPATH remove extra spaces in concatenation of elements

In XPATH, I am treating a source XML that looks like below, where I want to concatenate the child elements of each editor with a space delimiter to create a full name, and then in turn concatenate the resulting full names with commas:

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

Currently the XPATH (within XQuery) code looks like this, using XPATH map to introduce delimiters:

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>

But this outputs extra space before and after the commas:

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

Rather, I want to output:

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

Thanks in advance.

Upvotes: 1

Views: 93

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167571

"where I want to concatenate the child elements of each editor" would translate into $auth/* and not into $auth//child::text().

Somehow the whole mix of for return and ! and string-join looks odd, it seems you can just use string-join($bibref//tei:editor/string-join(*, ' '), ', ').

Upvotes: 2

Related Questions