Subject: [xsl] sorting question From: "Oliver Rutherfurd" <fruhstuck@xxxxxxxxxxxxxx> Date: Wed, 7 Mar 2001 14:34:36 -0500 |
Hello, I'm trying to transform a list of elements into a sorted set of pairs, and haven't been able to determine how to get the 'next' sorted element relative to the current position. As I couldn't get it to work with 'real' data, I simplified it to make it easier to play with (and explain). Below is a little xml and the xsl I'm trying to use. Any tips or hints would be great! here's a little data: <ALPHABET> <LETTER>a</LETTER> <LETTER>d</LETTER> <LETTER>b</LETTER> <LETTER>c</LETTER> </ALPHABET> I would like results like: (a,b)(c,d) The following selects the second element based on it's position in nodeset, not the sorted nodeset. <xsl:variable name="letters" select="/ALPHABET/LETTER" /> <xsl:for-each select="$letters"> <xsl:sort select="." /> <xsl:if test="(position() mod 2) = 1"> <xsl:variable name="next_index" select="number(position() + 1)" /> <!--[<xsl:value-of select="position()" />,<xsl:value-of select="$next_index" />]--> (<xsl:value-of select="." />,<xsl:value-of select="$letters[$next_index]" />) </xsl:if> </xsl:for-each> I checked out the xsl faq, and I found a posting of Jeni's that showed how to copy a sorted list into a variable, but it doesn't seem to be working for me. (I'm using MSXML3 in case that matters...) <xsl:variable name="letterlist"> <xsl:for-each select="/ALPHABET/LETTER"> <xsl:sort select="." /> <xsl:copy-of select="." /> </xsl:for-each> </xsl:variable> <!-- nothing comes out... --> <xsl:value-of select="$letterlist" /> Thanks, -Ollie Rutherfurd fruhstuck@xxxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] <br /> tag is condensed t, Roger Campbell | Thread | RE: [xsl] sorting question, Michael Kay |
RE: [xsl] MSXML ancestor-or-self, Chris Bayes | Date | RE: [xsl] [exsl] EXSLT 1.0 - Common, Kaganovich, Yevgeniy |
Month |