RE: [xsl] Dynamically define number of xsl:sort stmts using parameters

Subject: RE: [xsl] Dynamically define number of xsl:sort stmts using parameters
From: "Angela Williams" <Angela.Williams@xxxxxxxxxxxxxxxxxx>
Date: Wed, 28 Mar 2007 11:03:02 -0500

My esteemed colleague came up with a better idea - gosh, I hate it when
I forget the power of xpath!

<?xml version="1.0" encoding="UTF-8"?>
  <employee hireDate="04/23/1999">

  <employee hireDate="09/01/1998">

  <employee hireDate="08/20/2000">

  <sort order="1">last</sort>
  <sort order="2">first</sort>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="";
version="2.0" xmlns:saxon="";>

  <xsl:output method="text" />

  <xsl:template match="employees">
    <xsl:variable name="sort1" select="sort[@order='1']" />
    <xsl:variable name="sort2" select="sort[@order='2']" />
    <xsl:variable name="sort3" select="sort[@order='3']" />
    <xsl:variable name="sort4" select="sort[@order='4']" />

    <xsl:for-each select="employee">
          select="if ($sort1) then saxon:evaluate($sort1) else 'foo'" />
          select="if ($sort2) then saxon:evaluate($sort2) else 'foo'" />
          select="if ($sort3) then saxon:evaluate($sort3) else 'foo'" />
          select="if ($sort4) then saxon:evaluate($sort4) else 'foo'" />

      Last: <xsl:apply-templates select="last" />
      First: <xsl:apply-templates select="first" />
      Salary: <xsl:apply-templates select="salary" />
      Hire Date: <xsl:apply-templates select="@hireDate" />

-----Original Message-----
From: Angela Williams
Sent: Tuesday, March 27, 2007 12:59 PM
To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
Subject: RE: [xsl] Dynamically define number of xsl:sort stmts using

Thanks for both of your quick responses.  You've confirmed I am on the
right path.  There is a lot to think about.

Charles Knell wrote:
>use a stylesheet to create a stylesheet that does the transformation.

I think this would be possible, if complicated.  The user is not limited
on the number of tables they can insert, so there could be several
templates generated. It seems I would still end up with a variation of
3, as I would want to consolidate the number of templates to a minimum,
since the user could specify multiple tables with the same number of
sort statements. This would also mean I would have to output the master
stylesheet on the fly, too, to get the list of includes correct.

> (Do your users check off the columns they want to sort by in some user


Abel Braaksma wrote:
> I looked up an old template of myself where I faced a similar problem.

>The easy part is the number of sort statements. Just limit the amount
>to, say, 10, and create 10 sort statements.

This would certainly be the most expedient solution in the short term.


Current Thread