Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 19th, 2008, 03:48 PM
Authorized User
 
Join Date: May 2007
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default Selecting highest count

I have the following XML:

<curve>
    <data>
        <x>1</x>
         <y>5</y>
    </data>
</curve>
<curve>
    <data>
        <x>1</x>
         <y>5</y>
    </data>
</curve>
<curve>
    <data>
        <x>1</x>
         <y>5</y>
    </data>
    <data>
        <x>1</x>
         <y>5</y>
    </data>
</curve>

Note that the first two <curve>s contain one <data>, and the last <curve> contains two <data> elements.

I am trying to write an XPath expression that would return the highest <curve>/<data> count. In this instance, it would return 2. If another <curve> existed that contained 6 <data> elements, the expression would return 6.

I can come up with some bloated XSLT code using <xsl:for-each> to finally get to the number, but I know there must be a simpler way using XPath 2.0.

BTW, I am using Saxon8.

Any help is greatly appreciated.
 
Old November 19th, 2008, 03:55 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

max(curve/count(data)))

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old November 19th, 2008, 04:00 PM
Authorized User
 
Join Date: May 2007
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks! That is exactly what I needed.





Similar Threads
Thread Thread Starter Forum Replies Last Post
finding highest value Aprile Access VBA 3 October 3rd, 2007 07:13 AM
Finding the highest amount keithd Excel VBA 2 May 25th, 2005 01:44 PM
Finding the highest value of a query ry Oracle 1 December 18th, 2004 12:40 PM
Display highest test score kgs51 VB.NET 2002/2003 Basics 15 November 19th, 2004 11:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.