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

Re: Output sorted XHTML table for a subset of elements

Subject: Re: Output sorted XHTML table for a subset of elements
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Sun, 25 May 2008 12:53:57 +0200
Re:  Output sorted XHTML table for a subset of elements
Steven Davies wrote:

I know my sample data was a bit small but there are a lot more nodes in
my actual data set. Here's an attempt at a better example:

  <user name="alf"><lines>7</lines></user>
  <user name="bert"><lines>78</lines></user>
  <user name="charlie"><lines>731</lines></user>
  <user name="derek"><lines>62</lines></user>
  <user name="edward"><lines>93</lines></user>
  <user name="fred"><lines>823</lines></user>
  <user name="george"><lines>42</lines></user>
  <user name="harry"><lines>28</lines></user>
  <user name="ian"><lines>553</lines></user>
  <user name="joshua"><lines>92</lines></user>
  <user name="kevin"><lines>108</lines></user>
  <user name="luke"><lines>192</lines></user>

should give the output:

    <td>fred (823)</td>
    <td>charlie (731)</td>
    <td>ian (553)</td>
    <td>luke (192)</td>
    <td>kevin (108)</td>
    <td>edward (93)</td>
    <td>joshua (92)</td>
    <td>bert (78)</td>
    <td>derek (62)</td>
    <td>george (42)</td>
    <td>harry (28)</td>

Here is an XSLT 1.0 stylesheet making use of exslt:node-set:


<xsl:output method="html" indent="yes"/>

<xsl:param name="cols" select="5"/>

<xsl:param name="min-lines" select="25"/>

  <xsl:template match="/">
        <xsl:apply-templates select="users"/>

<xsl:template match="users">
<xsl:variable name="sorted-users-rtf">
<xsl:for-each select="user[lines &gt; $min-lines]">
<xsl:sort select="lines" data-type="number" order="descending"/>
<xsl:copy-of select="."/>
<xsl:variable name="sorted-users" select="exsl:node-set($sorted-users-rtf)/data/user"/>
<xsl:apply-templates select="$sorted-users[position() mod $cols = 1]" mode="row"/>

<xsl:template match="user" mode="row">
<xsl:apply-templates select=". | following-sibling::user[position() &lt; $cols]" mode="cell"/>

  <xsl:template match="user" mode="cell">
      <xsl:value-of select="concat(@name, ' (', lines, ')')"/>


I think libXSLT supports exsl:node-set.


	Martin Honnen

Current Thread


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.
First Name
Last Name
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.