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 September 26th, 2005, 10:40 AM
Registered User
 
Join Date: Sep 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default sorting and picking the first set

Hello,

Sort is used to sort a set of data. However how can I use sort to pick up the biggest value?
Here is my xml data. I want to sort "antiCollisionData" by "separationFactor" and pick up the largest "interBoundary" of the three.

            <antiCollisionSet>
                <antiCollisionData>
                    <interBoundary>
                        <metres>2.09067</metres>
                    </interBoundary>
                    <seperationFactor>2090.67</seperationFactor>
                </antiCollisionData>
                <antiCollisionData>
                    <interBoundary>
                        <metres>2.97572</metres>
                    </interBoundary>
                    <seperationFactor>2975.72</seperationFactor>
                </antiCollisionData>
                <antiCollisionData>
                    <interBoundary>
                        <metres>2.06649</metres>
                    </interBoundary>
                    <seperationFactor>2066.49</seperationFactor>
                </antiCollisionData>
            </antiCollisionSet>


Can you help me with this?

here is my xsl (but it doesnt work):

<xsl:for-each select="antiCollisionSet">
   <xsl:sort select="antiCollisionData/seperationFactor"/>
     <xsl:value-of select="antiCollisionData/interBoundary/metres"/>
</xsl:for-each>

thanx
 
Old September 26th, 2005, 10:48 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

xsl:for-each select="antiCollisionSet" is only going to select one element, and sorting a set containing one element isn't going to do much good.

You want

xsl:for-each select="antiCollisionSet/antiCollisionData"
  xsl:sort select select="separationFactor" (or however you choose to misspell it)

I'm confused about the relationship of separationFactor to interboundary/metres - are they always directly related?

To choose the largest value, do

<xsl:if test="position()=last()">
  <xsl:value-of select="."/>
</xsl:if>

inside the for-each, after the xsl:sort.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 27th, 2005, 04:13 AM
Registered User
 
Join Date: Sep 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx Michael,

That was very helpful (even the spelling tip ).

separation factor is related to the interboundary. I just removed some data from the xml example that i gave just to make it a simpler example.

Thanx again,






Similar Threads
Thread Thread Starter Forum Replies Last Post
Picking mail from Inbox sanjepau Biztalk 0 July 28th, 2007 08:42 AM
Need help picking a class 38ffems Intro Programming 5 April 29th, 2007 11:14 AM
Sorting in SJIS Charater set kribalas SQL Language 0 October 27th, 2006 03:46 AM
brand newbie - picking out values forkhead XML 2 August 19th, 2005 05:02 PM
xpath not picking up first element darrenclump XSLT 7 October 13th, 2003 11:36 PM





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