[xsl] Choosing different sorts

Subject: [xsl] Choosing different sorts
From: AWK <ncam_tech@xxxxxxxx>
Date: Tue, 11 Feb 2003 16:07:07 -0500
I'm trying to sort data based on value assigned when the stylesheet
evaluates a string and running into problems.  I'll give some sample xml and
then what I'm trying to accomplish.

<?xml version="1.0" ?>
<page url="http://www.foo.com/foo.html";>
    <issue weight="2"/>
<page url="http://www.foo.com/index.html";>
    <issue weight="3"/>
<page url="http://www.foo.com/boo.html";>
    <issue weight="12"/>
<page url="http://www.foo.com/foo/index.html";>
    <issue weight="3"/>

I want to create a table with three columns, with each page in its own row.
The url in column one, "index" in the second column of the row only if the
page ends in index.html (nothing otherwise), and the product of the
page/issue/@weight and either 1 or 2, depending on whether the page is an
index or not.  (e.g. Row 2 would read: www.foo.com/index.html  index  6)

So far, I can do all of this, but what I can't do is sort the list by the
third column.  I want to do an <xsl:if> immediately within the
<xsl:for-each> to create a variable which would be referenced by an
<xsl:sort> but the sort needs to be before the <xsl:if> and when it is
before the if it can't recognize the variable.

So how can I sort by a variable that hasn't been created or by a value that
needs to be calculated when the variable can't be global when the sort line
comes first?

Here's what I've tried most recently:

<xsl:template match="report">
<xsl:for-each select="page">

    <xsl:sort select="$isindex*@weight"/>

    <xsl:if test="substring(@url, (string-length(@url) -
        <xsl:variable name="isindex" select="2"/>

    ...table generation here...



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread