xqueryosb

How to get the child element data in a single string using xQuery


Below is the useCase

Input xml

<ns1:InvAdjRMS xmlns:ns1="www.thesourcethe.org">
  <ns1:FHEAD_Root>
    <ns1:FHEAD>FHEAD</ns1:FHEAD>
    <ns1:Lineid>0000000001</ns1:Lineid>
  </ns1:FHEAD_Root>
  <ns1:INADJ_Root>
    <ns1:INADJ>INADJ</ns1:INADJ>
    <ns1:Lineid>0000000003</ns1:Lineid>
  </ns1:INADJ_Root>
  <ns1:INADJ_Root>
    <ns1:INADJ>INADJ</ns1:INADJ>
    <ns1:Lineid>0000000004</ns1:Lineid>
  </ns1:INADJ_Root>
</ns1:InvAdjRMS>

Output String

FHEAD000000000120230803133049
INADJ0000000003
INADJ0000000004

how to achieve this using xQuery

I tried using concat


Solution

  • It is not clear where the 20230803133049 comes from; the following

    declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
    
    declare option output:method 'text';
    declare option output:item-separator '&#10;';
    
    /*/*/string-join(*)
    

    would give you

    FHEAD0000000001
    INADJ0000000003
    INADJ0000000004