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

Sorted node set and following-sibling axis

Subject: Sorted node set and following-sibling axis
From: "Nick Fitzsimons" <nick@xxxxxxxxxxxxxx>
Date: Wed, 10 Aug 2005 18:11:02 +0100 (BST)
give div priority
Hi,

I've got a problem which I think may be beyond the powers of XSLT 1, but
maybe somebody can help me out.

The simplified structure of the data is as follows:

<articles>
  <article priority="3">
    <title>second</title>
  </article>
  <article priority="9">
    <title>first</title>
  </article>
  <article priority="1">
    <title>last</title>
  </article>
  <article priority="3">
    <title>third</title>
  </article>
</articles>

and I need to output it sorted on the "priority" attribute. Note that
a) a higher value of priority is sorted to the top of the output
(descending sort);
b) some articles have the same priority, in which case they are output in
source order;
c) values for priority are not necessarily contiguous.

There isn't a problem in the simple case:

<xsl:template match="articles">
  <xsl:apply-templates select="article">
    <xsl:sort select="@priority" data-type="number" order="descending" />
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="article>
  <p><xsl:value-of select="title" /></p>
</xsl:template>

will give

<p>first</p>
<p>second</p>
<p>third</p>
<p>last</p>

However, what I require is the following:

<div>
  <p>first</p>
  <p>second</p>
</div>
<div>
  <p>third</p>
  <p>last</p>
</div>

The problem is that something like the following won't work:

<xsl:template match="article>
  <div>
    <p><xsl:value-of select="title" /></p>
    <p><xsl:value-of select="following-sibling::article/title" /></p>
  </div>
</xsl:template>

as the following-sibling axis returns the nodes in original document
order, not sorted order.

Any suggestions as to how I can achieve the desired output would be
appreciated.

(Unfortunately, the obvious solution of converting the data so that the
article elements are sorted before I get my hands on it won't work, as
this is legacy data, and the idea is precisely to avoid having to do
that... something to do with saving money on the back end.)

Thanks in advance for any suggestions,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/

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.