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

Choosing different sorts

Subject: Choosing different sorts
From: AWK <ncam_tech@xxxxxxxx>
Date: Tue, 11 Feb 2003 16:07:07 -0500
awk sort
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.

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

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) -
string-length('index.html'))+1='index.html'">
        <xsl:variable name="isindex" select="2"/>
    </xsl:if>

    ...table generation here...

    </xsl:for-each>
</xsl:template>


Thanks,
Andrew


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