tags:

views:

56

answers:

3

Hi there

I have the following XML:

<data>
    <page id="1118">
        <itms>
            <values>
                <value>1104</value>
            </values>
        </itms>
    </page>
    <page id="1177">
        <itms>
            <values>
                <value>1273</value>
                <value>1215</value>
            </values>
        </itms>
    </page>
</data>

I need to get the @id from the < page >, where a certain value is present in one of the < value >-tags. The id that need to be in the < value > is kept in this: $itm/@id.

This means that if my $itm/@id is equal to 1273, I need to get 1177 returned. I'm not quite sure how to achieve this.

Actually I could have XML that looks like this as well:

<data>
    <page id="1118">
        <itms>
            <values>
                <value>1104</value>
            </values>
        </itms>
    </page>
    <page id="1177">
        <itms>
            <values>
                <value>1273</value>
                <value>1215</value>
            </values>
        </itms>
    </page>
    <page id="1352">
        <itms>
            <values>
                <value>1242</value>
                <value>1273</value>
            </values>
        </itms>
    </page>
</data>

If that's the case, I need the latest id, so this means that if the $itm/@id matches values in more < page >'s, then I need to grab the value from the latest page. I the above case that would be 1352.

Hope this makes sense to you guys. And by the way, I work with Umbraco CMS if that does any difference.

Best Regards, Kim

+2  A: 

Something like page[itms/values/value=$itm/@id][last()]/@id.

lexicore
+1  A: 

my version: /data/page[itms/values/value/text()=$itm/@id][last()]/@id

philcolbourn
+3  A: 

You can use this

(/data/page[itms/values/value = 1273])[last()]/@id

or even this

(//value[.=1273])[last()]/ancestor::page[1]/@id
Tomalak
OBTW: The literal `1273` can of course be replaced by a variable.
Tomalak