This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
sort nodes based in value attribute
- To: "'xsl-list at mulberrytech dot com'" <xsl-list at mulberrytech dot com>
- Subject: sort nodes based in value attribute
- From: Roberto Marinero <rmarinero at renacimiento dot com>
- Date: Wed, 26 Apr 2000 18:03:01 +0200
- Reply-To: xsl-list at mulberrytech dot com
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