tags:

views:

32

answers:

2

I'm trying to write an expression that will return the priority for for a filtered value. So far I've been able to get correct results when filtering for the attribute to return the value, but not the reverse. Any help with this?

//Test/FileTypes/FileType[@Priority = '10'] returns person

//Test/FileTypes/FileType/@Priority returns the three attribute values (10,11,20)

//Test/FileTypes/FileType[FileType = 'Person']/@Priority returns nothing

<?xml version="1.0" encoding="utf-8" ?>

<Test>
    <FileTypes>
        <FileType Priority="10">Person</FileType>
        <FileType Priority="11">Job</FileType>
        <FileType Priority="20">Check</FileType>
    </FileTypes>
</Test>
+3  A: 

Try:

//Test/FileTypes/FileType[text() = 'Person']/@Priority

jimmy_keen
+3  A: 

//Test/FileTypes/FileType[FileType = 'Person']/@Priority returns nothing

As it should. A FileType doesn't have a child named FileType.

Use:

/Test/FileTypes/FileType[.= 'Person']/@Priority

Dimitre Novatchev
Thanks, this worked great. What does the .= mean though?
Jarek
@Jarek, `.` is the abbreviation for the context node (or for `self::node()`). `. = 'Person'` evaluates to the boolean value (true() of false()) of comparing the string value of the context node with the string `'Person'`.
Dimitre Novatchev