Subject: RE: [xsl] sorting by comparing two nodes From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Wed, 21 Dec 2005 00:39:05 -0000 |
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: [xsl] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] sorting by comparing two , Ragulf Pickaxe | Thread | [xsl] sorting by comparing two node, Claus Nagel |
RE: [xsl] Date Difference, Michael Kay | Date | RE: [xsl] Date Difference, Michael Kay |
Month |