[xquery-talk] return only latest version of an item
G. Ken Holman
gkholman at CraneSoftwrights.com
Thu May 14 15:23:24 PDT 2009
At 2009-05-14 14:18 -0400, A. Steven Anderson wrote:
>I've got a pretty complex xquery that returns only the latest
>version of all items in a collection, but I know there has got to be
>a more efficient way to do it.
>...
>What would be the most efficient way to do this?
By which criteria are you trying to measure efficiency?
Below is an example using max()
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
/items/item[version=max(/items/item/version)]
t:\ftemp>xquery steven.xml steven.xq con
<?xml version="1.0" encoding="UTF-8"?>
<item>
<id>1</id>
<name>item # 1</name>
<version>3</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:gkholman at CraneSoftwrights.com
Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/q/bc
Legal business disclaimers: http://www.CraneSoftwrights.com/legal
More information about the talk
mailing list