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

Re: html table of sorted element names

Subject: Re: html table of sorted element names
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Fri, 31 Oct 2003 10:28:25 +0100
html select sorted
I cannot reproduce your problem at all:

This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:exsl="http://exslt.org/common"
 exclude-result-prefixes="exsl"
 >
  <xsl:output omit-xml-declaration="yes" indent="yes"/>

  <xsl:template match="/db">
    <xsl:if test="1">
      <xsl:variable name="sortedelements">
        <xsl:for-each select="*">
          <xsl:sort data-type="text" select="name()"/>
          <xsl:copy-of select="."/>
        </xsl:for-each>
      </xsl:variable>
      <xsl:variable name="sortedelementsNodeSet"
                    select="exsl:node-set($sortedelements)/*"/>
      <table>
        <xsl:for-each select="$sortedelementsNodeSet[position() mod 4 = 1]">
          <tr>
            <xsl:for-each select=".|following-sibling::node()[position()
&lt; 4]">
              <td>
                <xsl:value-of select="name()"/>
              </td>
            </xsl:for-each>
          </tr>
        </xsl:for-each>
      </table>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>

when applied on this source.xml:

<db>
  <a>aaa</a>
  <c>ccc</c>
  <b>bbb</b>
  <e>eee</e>
  <d>ddd</d>
  <i>iii</i>
  <f>fff</f>
  <k>kkk</k>
  <m>mmm</m>
  <h>hhh</h>
  <j>jjj</j>
</db>

produces the wanted result:

<table>
  <tr>
    <td>a</td>
    <td>b</td>
    <td>c</td>
    <td>d</td>
  </tr>
  <tr>
    <td>e</td>
    <td>f</td>
    <td>h</td>
    <td>i</td>
  </tr>
  <tr>
    <td>j</td>
    <td>k</td>
    <td>m</td>
  </tr>
</table>

I got this result with many different XSLT processors, including xsltProc:

"Using libxml 20504, libxslt 10027 and libexslt 718
xsltproc was compiled against libxml 20504, libxslt 10027 and libexslt 718
libxslt 10027 was compiled against libxml 20504
libexslt 718 was compiled against libxml 20504"


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


"Saverio Perugini" <sperugin@xxxxxxxxxxxxxxxx> wrote in message
news:Pine.LNX.4.50.0310302330500.20921-100000@xxxxxxxxxxxxxxxx
> Hello,
>
> I'd like to produce a 4 column HTML table where the
> text contained in each <td> element is alphabetically
> sorted from cell (1,1) to cell (n,4),
> where n is the required number of rows.
>
> The following is an attempt:
>
> <xsl:template match="/db">
>    <xsl:if test="*[some condition]">
>       <xsl:variable name="sortedelements">
>          <xsl:for-each select="*">
>             <xsl:sort data-type="text" select="name()"/>
>             <xsl:copy-of select="."/>
>          </xsl:for-each>
>       </xsl:variable>
>
>       <xsl:variable name="sortedelementsNodeSet"
>                     select="exsl:node-set($sortedelements)/*"/>
>       <table>
>          <xsl:for-each select="$sortedelementsNodeSet[position() mod 4 =
1]">
>             <tr>
>                <xsl:for-each
select=".|following-sibling::node()[position() &lt; 4]">
>                    <td><xsl:value-of select="name()"/></td>
>                </xsl:for-each>
>             </tr>
>          </xsl:for-each>
>       </table>
>    </xsl:if>
> </xsl:template>
>
> While this produces a table, not all rows contain four columns, and even
> worse, the text contained in the <td>'s is not sorted across all <td>'s.
>
> I am using libxslt, which supports the node-set() exslt function.
> Does anyone see what is going wrong here?
>
> Thanks,
> Saverio
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>




 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-2011 All Rights Reserved.