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

Re: Choosing different sorts

Subject: Re: Choosing different sorts
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 11 Feb 2003 22:13:46 +0000
temporary result tree xslt
Hi Andrew,

> 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?

You can't solve the problem in that way. There are three solutions
that you might try.

The first is to use a fairly complex XPath expression to do the
condition for you. Try:

  <xsl:sort select="issue/@weight *
                    (1 + (substring(@url, string-length(@url) - 9) =
                          'index.html'))" />

If the url ends with 'index.html' then you get issue/@weight * 2; if
not then you get issue/@weight * 1.

The second is to write a user-defined function to work out the value
that you want for the third column. Depending on your processor, you
might have to use JavaScript to write the function or you might be
able to use <func:function> from EXSLT to write it using XSLT.

The third is to create a temporary result tree fragment that contains
a copy of the source document but with an extra attribute on the
<page> elements to give the value that you want for the third column.
You can convert this RTF into a node set using an extension node-set()
function and then process that node set to get the output; the sort is
then simple because you can just refer to the new attribute you've
added.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.