[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

return only latest version of an item

G. Ken Holman gkholman at CraneSoftwrights.com
Thu May 14 17:39:21 PDT 2009


  return only latest version of an item
At 2009-05-14 16:06 -0400, A. Steven Anderson wrote:
>Unfortunately though, I tried your suggestion but only returned one 
>item which was had the greatest version of all items.

I thought Pavel's suggestion was just fine and, indeed, the result is 
more than one item (transcript below).

>As far as implementation, I'm querying eXist-db 1.2.5.
>
>Any other suggestions?

Find another processor?

BTW, your data set happens to have steadily increasing version values 
for each <id>.  If it is true that the last of each <id> has the 
highest version, this might execute even faster because it has no 
function call:

   /items/item[not(id=following-sibling::item[1]/id)]

It returns the same result as Pavel's.

I hope this helps.

. . . . . . . . . . Ken

t:\ftemp>type steven.xml
<items>
    <item>
       <id>1</id>
       <name>item # 1</name>
       <version>1</version>
    </item>
    <item>
       <id>1</id>
       <name>item # 1</name>
       <version>2</version>
    </item>
    <item>
       <id>1</id>
       <name>item # 1</name>
       <version>3</version>
    </item>
    <item>
       <id>2</id>
       <name>item # 2</name>
       <version>1</version>
    </item>
    <item>
       <id>2</id>
       <name>item # 2</name>
       <version>2</version>
    </item>
    <item>
       <id>3</id>
       <name>item # 3</name>
       <version>1</version>
    </item>
</items>

t:\ftemp>type steven.xq
for $item in /items/item
  where $item/version = max(/items/item[id = $item/id]/version)
  return $item


t:\ftemp>xquery steven.xml steven.xq
<?xml version="1.0" encoding="UTF-8"?>
<item>
       <id>1</id>
       <name>item # 1</name>
       <version>3</version>
    </item>
<item>
       <id>2</id>
       <name>item # 2</name>
       <version>2</version>
    </item>
<item>
       <id>3</id>
       <name>item # 3</name>
       <version>1</version>
    </item>
t:\ftemp>type steven2.xq
/items/item[not(id=following-sibling::item[1]/id)]
t:\ftemp>xquery steven.xml steven2.xq
<?xml version="1.0" encoding="UTF-8"?>
<item>
       <id>1</id>
       <name>item # 1</name>
       <version>3</version>
    </item>
<item>
       <id>2</id>
       <name>item # 2</name>
       <version>2</version>
    </item>
<item>
       <id>3</id>
       <name>item # 3</name>
       <version>1</version>
    </item>
t:\ftemp>

--
XQuery/XSLT/XSL-FO hands-on training - Los Angeles, USA 2009-06-08
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/q/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:http://x-query.com/mailman/listinfo/talk
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/q/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.