[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Sorting Two Dimensional Table

Subject: RE: Sorting Two Dimensional Table
From: "Scott Trenda" <Scott.Trenda@xxxxxxxx>
Date: Mon, 15 Oct 2007 09:56:02 -0500
RE:  Sorting Two Dimensional Table
Pierre,

Remember that you can use multiple <xsl:sort/> statements together. Try
something like this:

<xsl:template match="entry">
  <xsl:apply-templates select="key">
    <xsl:sort select="@name"/>
    <xsl:sort select="@value"/>
  </xsl:apply-templates>
  <xsl:apply-templates select="value"/>
</xsl:template>

~ Scott


-----Original Message-----
From: Pierre-Luc Bertrand [mailto:Pierre-Luc.Bertrand@xxxxxxxxxx]
Sent: Monday, October 15, 2007 9:41 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  Sorting Two Dimensional Table

Thanks Scott,

Hotmail is great !!
Again,
 
 
Hi,
 
I'm desperately trying to sort a two dimension table.
 
I have keys and values. I want to be able to sort by keys and then by value.
This is not a problem so far. The problem comes when I try to sort the keys
that I want to be sorted as well.
 
Example:
x y value
a a a
a b a
a a b
a b b
a a c
b b a
b a b
b b b
b a d

which is presented as follow:

<table>
 <titles>
  <key>a</key>
  <key>b</key>
  <value>halo_name</value>
 </titles>
 
 <entries>
  <entry>
   <key name="b" value="a" />
   <key name="a" value="b" />
   <value>d</value>
  </entry>
  <entry>
   <key name="a" value="a" />
   <key name="b" value="a" />
   <value>c</value>
  </entry>
  <entry>
   <key name="a" value="a" />
   <key name="b" value="a" />
   <value>b</value>
  </entry>
  <entry>
   <key name="a" value="a" />
   <key name="b" value="b" />
   <value>b</value>
  </entry>
  <entry>
   <key name="a" value="b" />
   <key name="b" value="a" />
   <value>b</value>
  </entry>
  <entry>
   <key name="a" value="a" />
   <key name="b" value="a" />
   <value>a</value>
  </entry>
  <entry>
   <key name="a" value="b" />
   <key name="b" value="b" />
   <value>a</value>
  </entry>
  <entry>
   <key name="a" value="a" />
   <key name="b" value="b" />
   <value>a</value>
  </entry>
  <entry>
   <key name="a" value="b" />
   <key name="b" value="b" />
   <value>b</value>
  </entry>
 </entries>
</table>
 
Th problem is that I don't know the keys beforhand neither how many of them I
have. So to show the title of my table, I use something like that:
 
<xsl:for-each select="titles/key">
<xsl:sort select="." />
<th bgcolor="#9acd32" align="left"><xsl:value-of select="." /></th>
</xsl:for-each>
<th bgcolor="cornflowerblue" align="left"><xsl:value-of select="titles/value"
/></th>
 
 
So that I know that my key titles are always sorted and then I put the data in
the same fashion
 
<xsl:for-each select="entries/entry">
<tr>
<xsl:for-each select="key">
<xsl:sort select="@name" />
<td align="left"><xsl:value-of select="@value" /></td>
</xsl:for-each>
<td align="left"><xsl:value-of select="value" /></td>
</tr>
</xsl:for-each>
 
 
So I'd like to sort my keys and then sort the data accordingly so that
visually the first column is sorted first and the second column second...
 
Help !
 
Thank you very much.
 
PL


> Date: Mon, 15 Oct 2007 09:15:58 -0500
> From: Scott.Trenda@xxxxxxxx
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  Sorting Two Dimensional Table
>
> Hey PL,
>
> Try sending that again? It looks like your examples got nerfed when you
> sent it.
>
>
> ~ Scott
>
>
> -----Original Message-----
> From: P L [mailto:happytchoum@xxxxxxxxxxx]
> Sent: Monday, October 15, 2007 9:10 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Sorting Two Dimensional Table
>
>
> Hi,
>
> I'm desperately trying to sort a two dimension table.
>
> I have keys and values. I want to be able to sort by keys and then by
> value. This is not a problem so far. The problem comes when I try to
> sort the keys that I want to be sorted as well.
>
> Example:
>
> x y value
>
> a a a
> a b a
> a a b
> a b b
> a a c
> b b a
> b a b
> b b b
> b a d
>
> which is presented as follow:
>
>
>
> a
> b
> halo_name
>
>
>
>
>
>
> d
>
>
>
>
> c
>
>
>
>
> b
>
>
>
>
> b
>
>
>
>
> b
>
>
>
>
> a
>
>
>
>
> a
>
>
>
>
> a
>
>
>
>
> b
>
>
>
>
> Th problem is that I don't know the keys beforhand neither how many of
> them I have. So to show the title of my table, I use something like
> that:
>
>
>
>
>
>
>
>
>
>
>
>
>
> So that I know that my key titles are always sorted and then I put the
> data in the same fashion
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> So I'd like to sort my keys and then sort the data accordingly so that
> visually the first column is sorted first and the second column
> second...
>
> Help !
>
> Thank you very much.
>
> PL
>
> _________________________________________________________________
> Envoie un sourire, fais rire, amuse-toi! Employez-le maintenant!
> http://www.emoticonesgratuites.ca/?icid=EMFRCA120
>

________________________________________
Envoie un sourire, fais rire, amuse-toi! Employez-le maintenant!

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.