XSLT: Get node where one certain value is present

Posted by Kim Andersen on Stack Overflow See other posts from Stack Overflow or by Kim Andersen
Published on 2010-03-31T09:27:47Z Indexed on 2010/03/31 9:33 UTC
Read the original article Hit count: 267

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about xslt

Related posts about umbraco