开发者

XML expression to return attribute for a filtered value

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>


//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


Try:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜