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

Table breaks AND multi-level sorting (and confusion)

Subject: Table breaks AND multi-level sorting (and confusion)
From: Rob Wygand <rob@xxxxxxxxxx>
Date: Tue, 06 Feb 2001 23:28:45 -0800
html table break
Hi,

I aplogize if this is covered in the FAQ, but I've been reading it for hours and have not yet been able to successfully apply what's there to my problem.

Given the following XML:

<response>
  <item type="a" name="abc"/>
  <item type="b" name="yyy"/>
  <item type="a" name="xyz"/>
  <item type="a" name="cde"/>
  <item type="b" name="aaa"/>
  ...
</response>

I need to generate to generate a table in HTML that is 5 columns wide, sorted fiorst by type and second by name such as this:

<table>
  <tr>
    <td>abc</td>
    <td>cde</td>
  </tr>
  <tr>
    <td>xyz</td>
    <td>aaa</td>
  </tr>
  <tr>
    <td>yyy</td>
    <td></td>
  </tr>
  ...
</table>

I have deduced that

<xsl:for-each select="item]position() mod 5 = 1]">
  <xsl:sort select="@name"/>
</xsl:for-each>

will get me every 5th sorted item, but when I try and get it's following-siblings, thing go all wacky as those are returned in document order.

The XSL I current have is as follows:

<xsl:template match="response">
  <table border="1" cellpadding="10" cellspacing="1">

  <xsl:for-each select="item[position() mod 5 = 1]">
    <xsl:sort select="@type"
              data-type="text"
              order="ascending"
              case-order="upper-first"/>

<xsl:sort select="@name"
data-type="text"
order="ascending"
case-order="upper-first"/>
<tr>
<xsl:apply-templates select=".|following-sibling::item[position() &lt; 5]">
<!-- hoping resorting worked, but it does not -->
<xsl:sort select="@type"
data-type="text"
order="ascending"
case-order="upper-first"/>
<xsl:sort select="@name"
data-type="text"
order="ascending"
case-order="upper-first"/>
</xsl:apply-templates>
</tr>
</xsl:for-each>
</table>
</xsl:template>


  <xsl:template match="item">
    <td align="center">

<xsl:choose>

        <xsl:when test="@type='a'">
        ...
        </xsl:when>

        <xsl:when test="@type='b'">
        ...
        </xsl:when>
      </xsl:choose>

    </td>
  </xsl:template>

Any pointers would be most appreciated..

Many thanks in advance!
rjw


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.