I have to fetch all attributes by name 'product-id' when the currency of that pricebook is 'GBP'. This expression is working fine when xpath is used. But when I use xpath3, it returns only the first matching value instead of all the values. All I need is an equivalent expression of xpath in xpath3
working xpath expression:
#[xpath:/pricebooks/pricebook[./header/currency ="GBP"]/price-tables/price-table/@product-id]
xpath expression I tried:
#[xpath3('/pricebooks/pricebook[./header/currency ="GBP"]/price-tables/price-table/@product-id',payload,'STRING')]
expected : [product1,product2,product4]
actual : product1
INPUT XML:
<pricebooks>
<pricebook>
<header pricebook-id="GB">
<currency>GBP</currency>
<display-name>name1</display-name>
</header>
<price-tables>
<price-table product-id="product1">
<amount quantity="1">24.0</amount>
</price-table>
</price-tables>
</pricebook>
<pricebook>
<header pricebook-id="NZ">
<currency>GBP</currency>
<display-name>name2</display-name>
</header>
<price-tables>
<price-table product-id="product2">
<amount quantity="1">38.00003</amount>
</price-table>
</price-tables>
</pricebook>
<pricebook>
<header pricebook-id="US">
<currency>USD</currency>
<display-name>name3</display-name>
</header>
<price-tables>
<price-table product-id="A215ZZ003">
<amount quantity="1">28.0</amount>
</price-table>
</price-tables>
</pricebook>
<pricebook>
<header pricebook-id="AU">
<currency>GBP</currency>
<display-name>name4</display-name>
</header>
<price-tables>
<price-table product-id="product4">
<amount quantity="1">30.0</amount>
</price-table>
</price-tables>
</pricebook>
</pricebooks>
Looks like the third parameter in your attempted use of
xpath3()
is wrong. Try usingNODESET
instead ofSTRING
since you mean to return multiple nodes.Quoted from the documentation :
BOOLEAN
: Returns the effective boolean value of the expression as ajava.lang.String
. Equivalent to wrapping the expression in a call of the XPathboolean()
function.STRING
: Returns the result of the expression converted to a string, as ajava.lang.String
. Equivalent to wrapping the expression in a call to the XPathstring()
function.NUMBER
: Returns the result of the expression converted to a double as ajava.lang.Double
. Equivalent to wrapping the expression in a call of the XPathnumber()
function.NODE
: Returns the result as a node object.NODESET
: Returns a DOMNodeList
object.