This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: xsl reorder



On Thu, Jan 25 '01 at 16:50, Sheeba Rajkumar wrote:
> Sorry I did not get your answer .
> Is this answer for Sorting or Reordering xsl output.
It's an hint how to find the answer for both. Reordering and resorting 
require parameter passing from the client ...

You can only sort in the XSL-T. To do so, you have to tell the XSL-T
according to with criteria it should sort:

XML:

<table>
  <item>
    <name>foo</name>
    <value>1</value>
    <quantity>blub</quantiy>
  </item>
  .
  . <!-- more item here -->
  .
</table>

XSLT:

.
.
.
<xsl:template match="table">
  <xsl:for-each select="item">
    <xsl:sort select="name"/>
    <!-- create output here or use apply template instead of for-each
    -->   
  </xsl:for-each>
</xsl:template>
.
.
.

This does only sort by name. To make it sort by either name, value or
quentity you must pass a parameter (e.g. "sortBy"):

XSLT:

<xsl:param name="sortBy">name</param>

.
.
.
<xsl:template match="table">
  <xsl:choose>
    <xsl:when test="$sortBy = 'value'">
      <xsl:for-each select="item">
        <xsl:sort select="value"/>
        <!-- create output here or use apply template instead of for-each
        -->   
      </xsl:for-each>
    </xsl:when>  
    <!-- when for $sortBy = 'name' and $sortBy = 'quantity' -->
  </xsl:choose>  
</xsl:template>
.
.
.

It would be a lot easier if you could use a parameter or variable in a
<xsl:sort /> but I was unable to do so (It's not allowed in the spec).

To do reordering you must do the same but make a parameter called (e.g.)
"order" where you list the order. The order must be taken care of in the
"create output here" part.

You have to figure out how the JavaScript must look like to reorder
using drag and drop (good luck, this is deeper magic of DHTML,
especially if you want it to be cross browser). I do reordering with
small arrows (not drag and drop) and only for IE5.5, but with out deeper
knowledge of DHTML it took me about 6 hours to write the user interface
(the XSLT was done in less than an hour).

Of cause you must know your input XML document (or the work required
will rise exponentially).


> I am using xml in Servlets with xsl and Javascript.
I used MXSML3, but should be the same for either case, the xsl-t works
with saxon and xalan the same way. BTW: what servlet are you using, I'll
have to port my stuff to php /w xslt extension soon.

> I am either not able to open your attatchment file.
It's an gnuPG signature, dont bother.

> Can you send me the source  code, if you have it.
While I have it and it's still mine, I'd like to sell it to the person I
wrote the stuff for (and it will become her property than), so sorry I
cant give it to you :-(


Cu,
    Goetz.

PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]