[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
On 01/03/2013 22:38, dvint@xxxxxxxxx wrote:
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
Re: [xsl] Complex XPath question
Subject: Re: [xsl] Complex XPath question From: David Carlisle <davidc@xxxxxxxxx> Date: Fri, 01 Mar 2013 22:55:06 +0000 |
On 01/03/2013 22:38, dvint@xxxxxxxxx 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Complex XPath question, dvint | Thread | Re: [xsl] Complex XPath question, dvint |
Re: [xsl] Support for lookaround re, Hermann Stamm-Wilbra | Date | Re: [xsl] Complex XPath question, dvint |
Month |