[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: sorting by comparing two nodes

Subject: RE: sorting by comparing two nodes
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 21 Dec 2005 00:39:05 -0000
sorting 2d points
xsl:sort requires an expression that delivers a scalar value on which you
can sort; there's no way of sorting by specifying a comparator function that
compares any two values.

However, I'm sure FXSL could be used to rustle up such a higher-order sort()
function that takes a comparator function as an operand.

However, assuming your comparator function is transitive then I would think
there is almost certainly some function of a point that delivers a scalar
value on which you can sort directly.

Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: Claus Nagel [mailto:claus.nagel@xxxxxxxxx] 
> Sent: 19 December 2005 21:05
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  sorting by comparing two nodes
> 
> Hi,
> I'm stuck with a sorting problem and hope to find some help here :-)
> 
> I have the following input:
> 
> <points>10 13,20 34,2 10,40 67</points>
> 
> This is a comma-separated list of 2d points. Each point consists of a
> x-coordinate and a y-coordinate, parted by a white-space.
> 
> And I have a reference point, eg.
> 
> <refpoint>3 2</refpoint>
> 
> Now I want to sort the list of points. To do so I have to compare two
> points and compute the following:
> result = (P1.x - P0.x)*(P2.y - P0.y) - (P2.x - P0.x)*(P1.y - P0.y)
> 
> (P0 -> reference point,
>  P1 -> one point of the list,
>  P2 -> another point of the list)
> 
> According to the value of "result", P1 and P2 shall be sorted 
> as follows:
> 
>  result < 0: P1 goes before P2
>  result > 0: P2 goes before P1
>  result = 0: no sorting required
> 
> Assume the following template:
> <xsl:template name="sort">
>   <xsl:with-param name="refpoint"/>
>   <xsl:with-param name="$points"/>
>     <xsl:for-each select="tokenize($points,',')">
>       <xsl:sort select="."/>
>       ......
>     </xsl:for-each>
> </xsl:template>
> 
> I can't compare two points within <xsl:sort/> the way I have to, can
> I? How can I solve my sorting problem using xslt?
> 
> Thanks for any ideas,
> Claus

Current Thread

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-2013 All Rights Reserved.