RE: Strange Sort...

Subject: RE: Strange Sort...
From: Brian Young <Brian.Young@xxxxxxx>
Date: Thu, 20 Jul 2000 17:04:30 -0400
Hello,

Thank you for the feedback, all of you.  : )

I ended up going with Michael Kay's concat() solution.  It was clever -- I would never have thought of it...  I guess that even though Y and @Y are strings at that point that I was thinking of them as numbers and it never occurred to me to try concat().

So, the solution (and I'm winging it here, since the example was hypothetical so the solution I give here is...):

*Assuming "Bucket" as the current node

<xsl:for-each select=".//*">
   <xsl:sort select="number(concat(Y, @Y))" data-type="number" order="ascending" />
   ...code...
</xsl:for-each>

You just have to be sure that you don't have a node with a child of Y *and* an attribute of Y.  Also, if it has neither would that cause a problem?  Perhaps more correct would be a select of ".//*[(Y)or(@Y)]" or somesuch on the xsl:for-each to guarantee the node has either one or the other.

Thank you very much for the help and very interesting solution!

Thanks,
   Brian Young


-----Original Message-----
From: Spychalski, Frank [mailto:frank.spychalski@xxxxxxx]
Sent: Wednesday, July 19, 2000 4:27 PM
To: 'xsl-list@xxxxxxxxxxxxxxxx'
Subject: RE: Strange Sort...


Hello,

I think the easiest way is chaining 2 XSLTs, the first copiest the y values
from children to attributes and the second XSLT sorts the results. 

But I'm curious if one of the xslt-gurus will come up with a solution that
works with one xslt.

bye
Frank

-
Work is the curse of the drinking class. (Oscar Wilde)
Frank Spychalski                   frank@xxxxxxxxxxxxx


->-----Original Message-----
->From: Brian Young [mailto:Brian.Young@xxxxxxx]
->Sent: Wednesday, July 19, 2000 11:51 AM
->To: 'xsl-list@xxxxxxxxxxxxxxxx'
->Subject: Strange Sort...
->
->
->Hello,
->
->I have the following XML hierarchy:
->
-><bucket>
->	<object id="first" x="35" y="10" />
->	<object id="second" x="15" y="58" />
->	<subbucket>
->		<object>
->			<id>third</id>
->			<x>28</x>
->			<y>145</y>
->		</object>
->	</subbucket>
->	<object id="fourth" x="65" y="27" />
-></bucket>
->
->Ok, enough with the funny looks.  I know that the use of id, 
->x, and y should be consistent as either children or an 
->attribute.  ; ).  But, this is what I'm dealing with now, 
->until I can get it changed.
->
->I'd like to be able to sort all four objects based on the 
->value of their "y"s, regardless of whether they are a child 
->or an attribute.  Is that possible?  Doing two sorts, with 
->one being the major and the other the minor will not work.  I 
->think it has to be in one xsl:sort.
->
->Any help is greatly appreciated.
->
->Thanks,
->   Brian Young


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread