I have this sample xml
<ProductSaleItem>
<ItemReference>100</ItemReference>
<Discount>
<Modifier>1</Modifier>
</Discount>
</ProductSaleItem>
<ProductSaleItem>
<ItemReference>101</ItemReference>
<Discount>
<Modifier>1</Modifier>
</Discount>
<Discount>
<Modifier>2</Modifier>
</Discount>
</ProductSaleItem>
<ProductSaleItem>
<ItemReference>102</ItemReference>
</ProductSaleItem>
and this xpath
//ProductSaleItem[Discount/Modifier]/ItemReference
i am hoping to get
100 101
but all i get is
100
It seems the two Discount is stopping the node from being included
How do i fix my Predicate please?
This is in mysql so uses xpath 1.0
select extractvalue( "<ProductSaleItem><ItemReference>100</ItemReference><Discount> <Modifier>1</Modifier></Discount></ProductSaleItem><ProductSaleItem> <ItemReference>101</ItemReference><Discount><Modifier>1</Modifier></Discount>
<Discount><Modifier>2</Modifier></Discount></ProductSaleItem><ProductSaleItem>
<ItemReference>102</ItemReference</ProductSaleItem>","//ProductSaleItem[*/Modifier]/ItemReference") bob;
I have tried online xpath parsers and some use xpath 2.0 which seems to work but mysql refuses to work.
2
Answers
In the end I used
//ProductSaleItem/Discount/Modifier/../../ItemReference
According to Mysql docs
extractvalue()
returns the first nodeAs suggested in the docs an iteration should be made (stored proc or similar)
May be getting the
Modifier
value could help as followsOutput: