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

RE: Re: Adjusting sorted list

Subject: RE: Re: Adjusting sorted list
From: TSchutzerWeissmann@xxxxxxxxxxxxxxxx
Date: Fri, 17 May 2002 09:52:22 +0100
maintain sorted list

Dimitre's method is a grouping method: you group the b elements and then run
through the group using position() to get the ranking.

It's also possible to maintain a variable containing one b per value of b
and use that as the means of knowing the rank of a b. The only advantage of
doing it this way is that you can group your b's any which way and still
know their rank.

Let's say you wanted to do this globally, ie, have only one ranking for b
elements applying to all of them. The variable can be global:

	<xsl:stylesheet version='1.0'

	<xsl:key name='bs' match ='b' use='@val'/>
	<xsl:variable name="uniqueBs" select='//b[count(. | key("bs",
@val)[1]) = 1]'/>
In your case you can be a bit more specific than "//b" - you could use
"/root/a/b" and that will get all b elements.

Now whenever you want to know the rank of a current b element you just do
	<xsl:value-of select='count($uniqueBs[@val &lt; current()/@val]) +
This could be within another grouping, for example one that created a table
with three columns.

Tom Weissmann

-----Original Message-----
From: Andrew Timberlake [mailto:andrew.lists@xxxxxxxxx]
Sent: 16 May 2002 17:43
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Re: Adjusting sorted list

I've been playing with this idea and have created an interesting side

Using source:
	    <b val="4">four</b>
	    <b val="9">nine</b>
	    <b val="6">six</b>
	    <b val="1">one</b>
	    <b val="8">eight</b>
	    <b val="6">six</b>
	    <b val="4">four</b>
	    <b val="7">seven</b>
	    <b val="9">nine</b>
	    <b val="5">five</b>
	    <b val="5">five</b>

And style sheet:
<xsl:stylesheet version="1.0" 
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:key name="kRanking" match="b" use="@val"/>
  <xsl:template match="/root/a">
     <xsl:for-each select="b[generate-id() 
       <xsl:sort select="@val" data-type="number"/>
       <xsl:variable name="vPos" select="position()"/>
       <xsl:for-each select="key('kRanking',@val)">
         <b rank="{$vPos}">
           <xsl:value-of select="."/>

I now get:
	<b rank="1">one</b>
	<b rank="2">four</b>
	<b rank="2">four</b>
	<b rank="3">six</b>
	<b rank="3">six</b>
	<b rank="4">seven</b>
	<b rank="5">eight</b>
	<b rank="6">nine</b>
	<b rank="6">nine</b>
	<b rank="1">five</b>
	<b rank="1">five</b>

What have I done???


On Thu, 2002-05-16 at 16:58, Dimitre Novatchev wrote:

> Bellow is the stylesheet that does this:
> <xsl:stylesheet version="1.0" 
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>  <xsl:output omit-xml-declaration="yes" indent="yes"/>
>  <xsl:key name="kRanking" match="b" use="."/>
>   <xsl:template match="/">
>     <a>
>      <xsl:for-each select="/a/b[generate-id() 
>                               = 
>                                generate-id(key('kRanking',.)[1])
>                                ]">
>        <xsl:sort select="." data-type="number"/>
>        <xsl:variable name="vPos" select="position()"/>
>        <xsl:for-each select="key('kRanking',.)">
>          <b rank="{$vPos}">
>            <xsl:value-of select="."/>
>          </b>
>        </xsl:for-each>
>      </xsl:for-each>
>     </a>
>   </xsl:template>
> </xsl:stylesheet>
> With your source xml it produces exactly the desires result:
> <a>
>    <b rank="1">1</b>
>    <b rank="2">4</b>
>    <b rank="2">4</b>
>    <b rank="3">6</b>
>    <b rank="3">6</b>
>    <b rank="4">7</b>
>    <b rank="5">8</b>
>    <b rank="6">9</b>
> </a>
> Hope this helped.
> Cheers,
> Dimitre Novatchev.
> __________________________________________________
> Do You Yahoo!?
> LAUNCH - Your Yahoo! Music Experience
> http://launch.yahoo.com
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
Andrew Timberlake
Digital Design Development
011 705 1737
082 415 8283

"If debugging is the process of removing bugs, 
then programming must be the process of putting them in."

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

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

Current Thread


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.
First Name
Last Name
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.