Jovan
Jovan

Reputation: 161

Select node based on other node attribute (if contains)

Hello can anyone help me how to do folowing in the code:

<?xml version="1.0" encoding="utf-8"?>
    <details>
        <signature id="sig1">
            <name>mr. Barry Smith</name>
            <telephone type="fixed">01234 123456</telephone>
            <telephone type="mobile">071234562</telephone>
        </signature>

        <signature id="sig2">
            <name>mr. Harry Smith</name>
            <telephone type="fixed">01234 123456</telephone>
        </signature>
    </details>

I find answer on "How can I find the names of people who have a mobile phone" /details/signature[telephone/@type = 'mobile']/name, - if i include full attribute value, but how could i include contains function in this. I tried:

/details/signature[telephone/[contains(@type,'mobile')]/name

but it wont work.

Upvotes: 0

Views: 33

Answers (1)

paul trmbrth
paul trmbrth

Reputation: 20748

What you want is probably:

/details/signature[telephone[contains(@type, 'mobile')]]/name

looking for a signature that has a telephone with a type attribute which value contains "mobile", and selecting the name child element of this signature

/details/signature[  telephone[  contains(@type, 'mobile')  ]  ]/name

Upvotes: 1

Related Questions