Xpath > How can I select a node based on both its attributes and content?

Posted by Andrew Kirk on Stack Overflow See other posts from Stack Overflow or by Andrew Kirk
Published on 2010-06-08T12:50:15Z Indexed on 2010/06/08 12:52 UTC
Read the original article Hit count: 355

Filed under:
|

Sample XML:

<assignments>
<assignment id="911990211" section-id="1942268885" item-count="21" sources="foo">
    <options>
        <value name="NumRetakes">4</value>
        <value name="MultipleResultGrading">6</value>
        <value name="MaxFeedbackAttempts">-1</value>
        <value name="ItemTakesBeforeHint">1</value>
        <value name="TimeAllowed">0</value>
    </options>
</assignment>
<assignment id="1425185257" section-id="1505958877" item-count="4" sources="bar">
    <options>
        <value name="NumRetakes">0</value>
        <value name="MultipleResultGrading">6</value>
        <value name="MaxFeedbackAttempts">3</value>
        <value name="ItemTakesBeforeHint">1</value>
        <value name="TimeAllowed">0</value>
    </options>
</assignment>
<assignments>

Using XPath, I would like to select all assignments/assignment/options/value nodes where the nodes "name" attribute is "MaxFeedbackAttempts" and the nodes content is "-1". That is to say, I want to return each node that looks like:

<value name="MaxFeedbackAttempts">-1</value>

I can get each assignments/assignment/options/value node with the specified attribute using:

//assignment/options/value[@name="MaxFeedbackAttempts"]

I am just not sure how to refine this path to also limit the results based on the nodes content. Is there any way to do this using XPath?

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xpath