0
<attributes>
  <attribute name="Mail Zone" property="alerts.p45" type="">
    <value>mailzone</value>
  </attribute>
  <attribute name="Employee Name" property="acm_alert_custom_attributes.cs11" type="">
    <value>employeename</value>
  </attribute>
  <attribute name="Manager Name" property="alerts.p23" type="">
    <value><managername></value>
  </attribute>

How can I select the node <value> based on the attribute "name" of the above XML using XPath?

1 Answer 1

6

Let's say you wanted to select the value element that is a child of the attribute whose name is "Employee Name".

The XPath expression for that is the following:

/attributes/attribute[@name="Employee Name"]/value

In XSL you can use it like this:

<xsl:value-of select="/attributes/attribute[@name='Employee Name']/value"/>

It's built up the following way. First you want to select a value attribute, whose parent is an attribute element, whose parent is the root (I'm assuming) attributes. The / operator indicates the parent-child relationship between elements. So an expression to select all value elements would be the following:

/attributes/attribute/value

With that as a base, you want to filter the result by some other attribute. In this case, you want to filter by the name attribute of the attribute element (your choice of names might make things hard to follow). Filtering is done with [] clauses on the elements you want to filter by. In your case that's the attribute element:

/attributes/attribute[]/value 

Now you need to put something in the filter. The @ symbol indicates attributes of the element you're filtering by, followed by the name of the attribute you want. Then you compare the attribute to some known value, to arrive at the above expression:

/attributes/attribute[@name='filter']/value
Sign up to request clarification or add additional context in comments.

6 Comments

I can't stand that verbose monster that XSL is, but XPath is just beautiful :) +1
Thankyou sooo much for the help when i need it urgently...Thanks once again :) :) :) :) :) :) :) :)
@kishore: No problem. I hope you come to Stack Overflow whenever you need help. I strongly advise you to take the time to learn more about XPath because it's a powerful tool without too complicated a syntax.
yea sure..i will learn it....i started using it today only.... and thanks for the help and advise :) :)
@Welbog: +1 Correct answer. But I would consider to edit the question's title and tags: strictly speaking this is an XPath question.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.