Subject: [xsl] Re: (xsl) processing siblings based on sorted order, not document order From: Dimitre Novatchev <dnovatchev@xxxxxxxxx> Date: Fri, 25 May 2001 20:59:59 -0700 (PDT) |
Hi Steve, There is a way to avoid copying the sorted nodes into an RTF and then having to use the whatever:node-set() function. The template implementation of the generic sort() function (see http://sources.redhat.com/ml/xsl-list/2001-05/msg01189.html), returns the resulting node-list as a string of positions (numbers of fixed length). You can use this to iterate through the sorted order in any direction. You'll simply replace: following-sibling::bar[position() < 3] with $nodes[position()=$sortResult[position()=$currentPosition + 1] | $nodes[position()=$sortResult[position()=$currentPosition + 2] I'd be glad to help if you have any problems with this. Cheers, Dimitre Novatchev. Stephen Cunliffe wrote: Problem: I have an xml node-set that resembles the following; <foo> <bar id="Red"/> <bar id="Orange"/> <bar id="Blue"/> <bar id="Green"/> <bar id="Yellow"/> <bar id="Purple"/> <bar id="Magenta"/> <bar id="Indigo"/> <bar id="Cyan"/> <bar id="Teal"/> ... </foo> I need to do (2) things. First, I need to sort by id. (not a problem) <table> <xsl:apply-templates select="foo/bar"> <xsl:sort select="@id" data-type="text" order="ascending"/> </xsl:apply-templates> </table> Second, place the (sorted) bar id's, in a table, 3 per row. E.g. <tr> <td>Blue</td><td>Cyan</td><td>Green</td> </tr> <tr> <td>Indigo</td><td>Magenta</td><td>Orange</td> </tr> <tr> <td>Purple</td><td>Red</td><td>Teal</td> </tr> <tr> <td>Yellow</td> </tr> So, the logic as I see it, would be to process through each "bar" (the siblings), and find the first item in every row,... <xsl:template match="bar"> <xsl:if test="position() mod 3 = 1"> <tr> <!-- apply a template here, where select=".|following-sibling::bar[position() < 3]" --> </tr> </xsl:if> </xsl:template> ::::: The issue, is that "position()" and "following-sibling" are in the xml document order [XPath] and thus the results are not sorted in the output. ====================================== Q.) Is there a way in XSLT / XPath to apply-templates / do a for-each, that will "select" based on sorted order vs. document order... or a way to create a new (sorted) node-set, without limiting myself to a specific Xalan / Saxon / XSLT Processor. Q2). If I *have* to use a specific XSLT Processor, anyone have a solution for Xalan? __________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XSL List, Gustaf Liljegren | Thread | [xsl] Re: (xsl) processing siblings, Dimitre Novatchev |
[xsl] Convert XML elements with ext, Xiaocun Xu | Date | [xsl] Re: (xsl) processing siblings, Dimitre Novatchev |
Month |