I have an XML file having structure like this:
<?xml version="1.0" encoding="UTF-8"?>
<hudson>
<authorizationStrategy>
<roleMap type="globalRoles">
<role name="Employees">
<assignedSIDs>
<sid>abc</sid>
<sid>bcd</sid>
</assignedSIDs>
</role>
</roleMap>
<roleMap type="projectRoles">
<role name="test1" pattern=".*">
<assignedSIDs>
<sid>abc</sid>
<sid>zxc</sid>
</assignedSIDs>
</role>
<role name="test2" pattern=".*">
<permissions/>
<assignedSIDs>
<sid>abc</sid>
<sid>ghi</sid>
</assignedSIDs>
</role>
<role name="test3" pattern=".*">
<permissions/>
<assignedSIDs>
<sid>abc</sid>
</assignedSIDs>
</role>
</roleMap>
</authorizationStrategy>
</hudson>
Previously, I didn't gave the whole structure in question and the xpath i got in solution, didn't gave the result what I expected (on my system, but it gave to the person who answered my question) in following link search tag attribute value based on child node value using XmlStarlet
AS mentioned in that link, I want to find role tag name attribute based on value of sid tag. for eg: if I search for abc, the query must return Employees, test1, test2 and test3.
Here's the script I used:
xmlstarlet sel -t -v "//role[.//sid = 'abc']/@name" test.xml
but it gave me only 'Employees'.
I am using LINUX /bash. Please tell me, what I am missing in XPATH expression.