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

Re: Sorted node set and following-sibling axis

Subject: Re: Sorted node set and following-sibling axis
From: JBryant@xxxxxxxxx
Date: Wed, 10 Aug 2005 13:51:27 -0500
following sibling axis sort
A slight improvement - the test for a following sibling is unnecessary, as 
the processor will just do nothing if it can't find a following sibling. 
Thus, the following stylesheet does just as well:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml" indent="yes"/>

  <xsl:variable name="articles">
    <xsl:for-each select="/articles/article">
      <xsl:sort select="@priority" data-type="number" order="descending"/>
      <p><xsl:value-of select="."/></p>
    </xsl:for-each>
  </xsl:variable>

  <xsl:template match="articles">
    <xsl:for-each select="$articles/p">
      <xsl:if test="position() mod 2 = 1">
        <div>
          <xsl:copy-of select="."/>
          <xsl:copy-of select="following-sibling::*[1]"/>
        </div>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

I usually just want something that works as a first step, and then I work 
on optimization (usually for maintainability rather than performance). 
This stylesheet is a case in point, I guess.

Jay Bryant
Bryant Communication Services
(presently consulting at Syngeristic Solution Technologies)

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.