Reputation: 185
Using the xpath statement shown with xmlstarlet, it does not honor the end of string anchor, and selects both 'aaa' and 'bbb'. How can do I structure the xpath statement to match on an attribute which ends with 998?
-v "../Property[contains(@Name, '998$')]
<Object>
<Property Name="1230-02324998">
<Value>aaa</Value>
</Property>
<Property Name="3223-99824993">
<Value>bbb</Value>
</Property>
</Object>
Upvotes: 0
Views: 565
Reputation: 22617
Tried this: xmlstarlet sel -B -t -m "//Object" -v "..Property[substring(@Name, string-length(@Name) - 2) = '998']" The answer should be: "aaa", but it didn't work.
Please be careful when typing answers to your questions into the shell. Martin Honnen did not tell you to start the expression with ..
, which makes it an invalid expression.
Given that your XML input is stored in an XML document called "object.xml":
$ xml sel -B -t -m "Object" -v "Property[substring(@Name, string-length(@Name) - 2) = '998']" object.xml
aaa
Upvotes: 0
Reputation: 167571
The contains
function does not have any regular expression support. Use Property[substring(@Name, string-length(@Name) - 2) = '998']
.
Upvotes: 1