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

sorting by comparing two nodes

Subject: sorting by comparing two nodes
From: Claus Nagel <claus.nagel@xxxxxxxxx>
Date: Mon, 19 Dec 2005 22:05:03 +0100
xsl sort by two
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.