[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Complex XPath question


Subject: Re: [xsl] Complex XPath question
From: Liam R E Quin <liam@xxxxxx>
Date: Fri, 01 Mar 2013 19:09:10 -0500

On Fri, 2013-03-01 at 14:38 -0800, dvint@xxxxxxxxx wrote:
> I have the following XML:
[...]

> <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'.

You mentioned elsewhere that you're using XSLT but not which version.

Here's an XQuery version:

(for $i in //object[match title here]
  order by property[@name eq "version"] descending
  return $i)[1]/id

David already suggested a way to match title elements.

In XPath we can do something like this, looking for an object such that
no other object has a higher version (assuming they all have versions):

//object[
  not(
   //object[property[@name eq "version"] > property[@name eq "version"]
  )]/id

but it might not be very fast...

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml


Current Thread
Keywords