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

sort nodes based in value attribute

Subject: sort nodes based in value attribute
From: Roberto Marinero <rmarinero@xxxxxxxxxxxxxxxx>
Date: Wed, 26 Apr 2000 18:03:01 +0200
sort nodes
Hi:
I'm novice with XSL-XML and I have a little problem. I work in MSXML for
IE5.
I would like build a HTML table which content is in the XML file below:

<root>
   <head>
      <col0 visible="1">head00</col0>
      <col1 visible="3">head01</col1>
      <col2 visible="2">head02</col2>
      .....
   </head>
   <tbody>
      <row>
          <col0>cont00</col0>
          <col1>cont01</col1>
          <col2>cont02</col2>
          .....
      </row>
      <row>
          <col0>cont10</col0>
          <col1>cont11</col1>
          <col2>cont12</col2>
          .....
      </row>
      ....
   <tbody>
</root>

The problem is the "visible" attribute. His value lead the position of
column in the result table. 

The final table in the above example will be:

<TABLE>
   <THEAD>
      <TH>head00</TH>
      <TH>head02</TH>
      <TH>head01</TH>
      ....
   </THEAD>
   <TBODY>
      <TR>
         <TD>content00</TD>
         <TD>content02</TD>
         <TD>content01</TD>
         .....
      </TR>
      <TR>
         <TD>content10</TD>
         <TD>content12</TD>
         <TD>content11</TD>
         .....
      </TR>
      .....
   </TBODY>
</TABLE>

I try with "order-by" from <xsl:for-each> like this:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

<xsl:template match="//root">
   <TABLE>
       <THEAD>
       <xsl:for-each select="head/node()" order-by="@visible">
          <TH><xsl:value-of select="text()" /></TH>
       </xsl:for-each>
       </THEAD>
       <TBODY>
       <xsl:apply-templates select="//tbody/row" />
       </TBODY>
   </TABLE>
</xsl:template>

<xsl:template match="tbody/row">
   <TR>
   <xsl:for-each select="node()" order-by="context(-1)/@visible">
      <TD><xsl:value-of select="text()" /></TD>
   </xsl:for-each>
   </TR>
</xsl:template>

The header of the table works fine. The columns in the header appears well
sorted, but the body show the columns in XML order. The
"order-by=context(-1)/@visible" d'ont work. why? The sort criteria in
'order-by' must be inside context pattern from 'select'? 

A solution would be populate all nodes with the "visible" attribute but it
could be very expensive in long tables. Any other solution?
 
Thanks in advance.
Roberto.




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


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.