0

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.

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

4 Comments

ok, can you tell me how it would be if i have one child under telephone i.e tr and then telephone type. i would like something like /details/signature[tr[0]/telephone[contains(@type, 'mobile')]]/name, then it wont work
Try /details/signature[.//telephone[contains(@type, 'mobile')]]/name
Tried that, but it seems contains function cant be implemented in this way? Am i right?
It should work. Can you post another example XML with this last use case?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.