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

Re: Re: Can grouping and sorting be done in single t

Subject: Re: Re: Can grouping and sorting be done in single transformation?
From: "Herman Kwok" <herman.kwok@xxxxxxxxxxxxxxxx>
Date: Tue, 18 Nov 2003 18:21:07 +0800
herman kwok
Sorry for my late reply as I was out of town.

Thanks Dimitre for the "exslt:node-set()" solution and Jarkko for the "xalan:nodeset()" solution.

Does it mean that there is no solution without using processor dependent solution nor external library in XSLT 1.0?

Well, I am new to XSLT. I suspect that there are some limitations in node set in XSLT. That was why the function was extended via using external library or via enhancing a processor. Am I correct?

How about in XSLT 2.0? Should I drove in some XSLT tutorials to extend my knowledge?

Highly appreciated if you can give me some recommendations.

----- Original Message -----
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Tue, 11 Nov 2003 21:11:11 +0100
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Re: Can grouping and sorting be done in single transformation?


"Herman Kwok" <herman.kwok@xxxxxxxxxxxxxxxx> wrote in message
news:20031110060052.4077.qmail@xxxxxxxxxxxx
> Hi all,
>
> I am new to XSL. I am woundering if sorting and grouping can be done in
single transformation. If it is possible, would you please tell me how?

Yes, if you use the exslt:node-set() extension function.

This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:ext="http://exslt.org/common"
 exclude-result-prefixes="ext"
 >
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:template match="result">
    <xsl:copy>
      <xsl:variable name="vrtfSorted">
        <xsl:for-each select="item">
          <xsl:sort select="@desc"/>
          <xsl:copy-of select="."/>
        </xsl:for-each>
      </xsl:variable>

      <xsl:variable name="vSorted"
          select="ext:node-set($vrtfSorted)/*"/>
      <xsl:for-each select="$vSorted">
        <xsl:if test="position() mod 3 = 1">
          <xsl:variable name="vPos" select="position()"/>
          <group>
            <xsl:copy-of select=". | $vSorted[position() > $vPos
                                            and
                                             position() < $vPos + 3
                                             ]"/>
          </group>
        </xsl:if>
      </xsl:for-each>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

when applied on your source.xml:

<result>
  <item desc="d"/>
  <item desc="j"/>
  <item desc="k"/>
  <item desc="e"/>
  <item desc="c"/>
  <item desc="g"/>
  <item desc="h"/>
  <item desc="i"/>
  <item desc="f"/>
  <item desc="a"/>
  <item desc="b"/>
</result>

produces the wanted result:

<result>
   <group>
      <item desc="a"/>
      <item desc="b"/>
      <item desc="c"/>
   </group>
   <group>
      <item desc="d"/>
      <item desc="e"/>
      <item desc="f"/>
   </group>
   <group>
      <item desc="g"/>
      <item desc="h"/>
      <item desc="i"/>
   </group>
   <group>
      <item desc="j"/>
      <item desc="k"/>
   </group>
</result>


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




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


-- 
__________________________________________________________
Sign-up for your own personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

Search Smarter - get the new eXact Search Bar for free!
http://www.exactsearchbar.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.