xsl-list
[Top] [All Lists]

Re: [xsl] Complex XPath question

2013-03-01 16:55:18
On 01/03/2013 22:38, dvint(_at_)dvint(_dot_)com wrote:
I have the following XML:

<wrapper>
<object class="Page" package="com.atlassian.confluence.pages">
        <id name="id">37716253</id>
        <property name="title">
                <![CDATA[COMPARE]]>
        </property>
        ...
        <property name="version">3</property>
        <property name="creatorName">
                <![CDATA[wbenica]]>
        </property>
        <property name="creationDate">2012-11-16 14:00:35.000</property>
</object>
<object class="Page" package="com.atlassian.confluence.pages">
        <id name="id">37716529</id>
        <property name="title">
                <![CDATA[COMPARE]]>
        </property>
        ...
        <property name="version">1</property>
        <property name="creatorName">
                <![CDATA[wbenica]]>
        </property>
        <property name="creationDate">2012-11-16 14:00:35.000</property>
</object>
<object class="Page" package="com.atlassian.confluence.pages">
        <id name="id">37716528</id>
        <property name="title">
                <![CDATA[COMPARE]]>
        </property>
        ...
        <property name="version">2</property>
        <property name="creatorName">
                <![CDATA[wbenica]]>
        </property>
</object>
<object class="Page" package="com.atlassian.confluence.pages">
        <id name="id">37716253</id>
        <property name="title">
                <![CDATA[SOME OTHER TITLE]]>
        </property>
        ...
        <property name="version">3</property>
        <property name="creatorName">
                <![CDATA[wbenica]]>
        </property>
        <property name="creationDate">2012-11-16 14:00:35.000</property>
</object>
</wrapper>

I want to find the <id> element value for the <object> element that has
the highest version <property> (of those matching the title) and matches the
title <property> element for 'COMPARE'.

The following matchs all <object>
elements that have a title and version:

//object[property[@name='title'] and property[@name='version']]

How do I look for a specific title and find the highest version? Is it
possible in one XPath statement?


Would be more efficient of you could use xslt and keys and variables and things but this seems to work, returns

<id name="id">37716253</id>

on your input.


for $m in max(//object[normalize-space(property[@name='title'])='COMPARE']/number(property[@name='version']))
return
//object[normalize-space(property[@name='title'])='COMPARE'][number(property[@name='version'])=$m]/id



(more pointless CDATA markup in your input document)

David


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>