Home > OS >  XPath string-join with apostrophs for dynamic value set
XPath string-join with apostrophs for dynamic value set

Time:02-02

i want to use XPATH to join a string. Actually i have a XML Structure like this:

<root>
 <employee>
  <employeePayrollID>1234567</employeePayrollID>
 </employee>
 <employee>
  <employeePayrollID>7654321</employeePayrollID>
 </employee>
 ...
</root>

I want to generate this output: '1234567','7654321'

I'm using SAP CPI Content-Modifier to save this output as a Property.

propName: keys

sourceType: XPath

sourceValue: string-join(//employeePayrollID,',')

dataType: java.lang.String

This leads to output: 1234567,7654321

The challenge is to get this ' around the Id's, because i need it for further logic. I know this can be done with XSLT and so on. I really want to do it within this one liner XPath. Any chance?

regards

CodePudding user response:

You can try one of the following two XPath-2.0 approaches:

  1. The inner-join:

    concat("&apos;",string-join(//employeePayrollID,"&apos;,&apos;"),"&apos;")
    
  2. The outer-join:

    string-join(for $emp in //employeePayrollID return concat("&apos;",$emp,"&apos;"),",")
    

Output should be as expected in both cases.
Switch the quotes if necessary.

  • Related