[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] Grooping and Sorting problem
Subject: RE: [xsl] Grooping and Sorting problem From: "McNally, David" <David.McNally@xxxxxxxxxx> Date: Thu, 28 Mar 2002 16:48:35 -0500 |
Fred, There is a solution involving d-o-e, but I wouldn't dare to suggest it. There's also a fairly easy solution using the node-set extension - just sort test nodes into a variable - then iterate over the node-set. For an XSLT 1.0 solution, you could try something like Jeni suggested here: http://www.biglist.com/lists/xsl-list/archives/200111/msg00784.html or you can try doing your own "node-set"ing, as below - basically this writes the generated ids of each test node in the sorted list to a string, with some delimiters and the position within the sorted list, and then iterates through the test nodes again, extracting each id in order from the string and using that to apply templates to the correct test node. <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <table> <xsl:variable name="leaves"> <xsl:text>;;0::</xsl:text> <xsl:for-each select="//test" > <xsl:sort select="@number" data-type ="number"/> <xsl:value-of select="generate-id(.)"/> <xsl:text>;;</xsl:text> <xsl:value-of select="position()"/> <xsl:text>::</xsl:text> </xsl:for-each> </xsl:variable> <xsl:for-each select="//test"> <xsl:if test="position() mod 5 = 1"> <xsl:variable name="pos"><xsl:value-of select="position()"/></xsl:variable> <tr> <xsl:for-each select="self::test | following-sibling::test[position() < 5]"> <xsl:variable name="thisId"> <xsl:value-of select="substring-before(substring-after($leaves,concat(';;',($pos + position() -2),'::')),concat(';;',($pos + position()-1),'::'))"/> </xsl:variable> <td> <xsl:apply-templates select="//*[generate-id(.) = $thisId]"/> <xsl:value-of select="//*[generate-id(.) = $thisId]/@number"/> </td> </xsl:for-each> </tr> </xsl:if> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet> I don't know how efficient this is, though. Hope this helps, David. -- David McNally Moody's Investors Service Software Engineer 99 Church St, NY NY 10007 David.McNally@xxxxxxxxxx (212) 553-7475 > -----Original Message----- > From: Frédéric Tremblay [mailto:ftremblay@xxxxxxxxxxxxxxx] > Sent: Thursday, March 28, 2002 2:58 PM > To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx' > Subject: RE: [xsl] Grooping and Sorting problem > > > Hi, > > thanks for the answer but the problem is: i want to sort all > elements > like you suggest and i want to make a table with 5 rows and n > column. To do > this > i try this: > > > <xsl:for-each select="test" > > > <xsl:sort select="@number" data-type ="number"/> > > <xsl:if test="position() mod 5 = 1"> > > <tr> > <xsl:for-each select="self::test | > following-sibling::test[position() < 5]"> > <td><xsl:apply-templates/><xsl:value-of > select="@number"/></td> > </xsl:for-each> > </tr> > > </xsl:if> > > </xsl:for-each> > > But the problems is the first element is sorted but the > following-sibling::test[position() < 5]" > is not sorted... > > So how can i, first sort all element and after grooping it > to make a table with 5 rows and n column? > > Thanks a lot! > > Fred --------------------------------------- The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission. If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited. If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments. Thank you. Every effort is made to keep our network free from viruses. You should, however, review this e-mail message, as well as any attachment thereto, for viruses. We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Grooping and Sorting prob, G. Ken Holman | Thread | [xsl] The filter and str-filter fun, Dimitre Novatchev |
Re: [xsl] Looping and assigning int, Peter Davis | Date | Re: [xsl] Oracle nodeset function, Steve Muench |
Month |
Keywords