xsl-list
[Top] [All Lists]

RE: [xsl] Sorting Two Dimensional Table

2007-10-16 08:25:48
<?xml-stylesheet type="text/xsl" href="test.xsl"?>

There are no stupid question... I'm not in a position to say that
questions are stupid ;)

Pierre

-----Original Message-----
From: Scott Trenda [mailto:Scott(_dot_)Trenda(_at_)oati(_dot_)net] 
Sent: Tuesday, October 16, 2007 11:22 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Sorting Two Dimensional Table

... Stupid question, but are you transforming it on the server side
first, or are you just putting an <?xml-stylesheet?> reference in your
XML and expecting IE to transform it?

~ Scott


-----Original Message-----
From: Pierre-Luc Bertrand 
[mailto:Pierre-Luc(_dot_)Bertrand(_at_)nuance(_dot_)com] 
Sent: Tuesday, October 16, 2007 10:19 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Sorting Two Dimensional Table

Hi,

Thanks for that answer but unfortunately, I can't get it to work. I
don't know if it is due to the fact that I'm using Internet Explorer to
see the transform but I'm getting this error:

'Reference to variable or parameter 'k1' must evaluate to a node list.'

I tried to debug it but I'm not too convinced of what I'm doing is good.

In the article http://www.dpawson.co.uk/xsl/sect2/N8090.html, question 4
(you wrote it), I'm suppose to get only one node but I think what we
want is a sorted nodelist of the keys. I'm not sure what the xs:string+
is but it seems to be a string. Is it possible that I should be using
something like what is described by Andrew Welch in
http://ajwelch.blogspot.com/2007/02/csv-to-xml-converter-in-xslt-20.html
to get a nodelist from the values that are concatenated (this is a guess
based on my understanding of question 6 by Jeni Tennison of
http://www.dpawson.co.uk/xsl/sect2/N8090.html )

If you can help me again to debug that one, it would be appreciated.

Thanks again.

Pierre

-----Original Message-----
From: David Carlisle [mailto:davidc(_at_)nag(_dot_)co(_dot_)uk] 
Sent: Monday, October 15, 2007 3:14 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Sorting Two Dimensional Table




<x>
<titles>
        <key>z</key>
        <key>a</key>
        <value>valueX</value>
</titles>



<entries>
  <entry>
    <key name="a" value="b" />
    <key name="z" value="c" />
    <value>myValue1</value>
  </entry>
  <entry>
    <key name="a" value="b" />
    <key name="z" value="d" />
    <value>5</value>
  </entry>
  <entry>
    <key name="a" value="a" />
    <key name="z" value="c" />
    <value>myValue3</value>
  </entry>
  <entry>
    <key name="a" value="b" />
    <key name="z" value="d" />
    <value>4</value>
  </entry>
</entries>
</x>


<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:xs="http://www.w3.org/2001/XMLSchema";
                exclude-result-prefixes="xs">
  
  <xsl:variable name="k1" as="xs:string+">
    <xsl:perform-sort select="x/titles/key">
      <xsl:sort select="."/>
    </xsl:perform-sort>
  </xsl:variable>

  <xsl:output indent="yes"/>

  <xsl:template match="x">
 

   <table>
     <tr>
       <xsl:for-each select="$k1,titles/value">
         <th><xsl:value-of select="."/></th>
       </xsl:for-each>
     </tr>

    <xsl:call-template name="entries">
      <xsl:with-param name="k" select="$k1"/>
      <xsl:with-param name="e" select="entries/entry"/>
    </xsl:call-template>
   </table>

  </xsl:template>

  <xsl:template name="entries">
    <xsl:param name="k"/>
    <xsl:param name="e"/>
    <xsl:choose>
      <xsl:when test="empty($k)">
        <xsl:apply-templates select="$e">
          <xsl:sort lang="en" select="value"/>
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        <xsl:for-each-group select="$e"
group-by="key[(_at_)name=$k[1]]/@value">
          <xsl:sort lang="en" select="key[(_at_)name=$k[1]]/@value"/>
          <xsl:call-template name="entries">
            <xsl:with-param name="k" select="$k[position()!=1]"/>
            <xsl:with-param name="e" select="current-group()"/>
          </xsl:call-template>
        </xsl:for-each-group>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

<xsl:template match="entry">
    <xsl:variable name="here" select="."/>
    <tr>
      <xsl:for-each select="$k1">
         <td><xsl:value-of
select="$here/key[(_at_)name=current()]/@value"/></td>
       </xsl:for-each>
       <td><xsl:value-of select="value"/></td>
    </tr>
</xsl:template>

</xsl:stylesheet>


$ saxon8 2dsort.xml  2dsort.xsl 
<?xml version="1.0" encoding="UTF-8"?>
<table>
   <tr>
      <th>a</th>
      <th>z</th>
      <th>valueX</th>
   </tr>
   <tr>
      <td>a</td>
      <td>c</td>
      <td>myValue3</td>
   </tr>
   <tr>
      <td>b</td>
      <td>c</td>
      <td>myValue1</td>
   </tr>
   <tr>
      <td>b</td>
      <td>d</td>
      <td>4</td>
   </tr>
   <tr>
      <td>b</td>
      <td>d</td>
      <td>5</td>
   </tr>
</table>

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>