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

Re: local extremums

Subject: Re: local extremums
From: "Ragulf Pickaxe" <jawxml@xxxxxxxxxxx>
Date: Wed, 19 Mar 2003 08:39:00 +0000
local extremas
Hi Evgenia,

Hello!

I have a problem with determining local extremums (precisely - local
maximums) of the list.

I mean I need to realize next algorithm:
1. take the list (it is //PoketTourList/Country/Range on first iteration)
2. determine the maximum @Cnt of this list
3. cast away this maximum and two his nearest neighbours
4. if line isn't empty than goto step 1
So I need a list with any flag showing Range is local extremum or not.
Or I need a way to go throw whole list and determine if each Range is local
extremum or not on every step.

The list structure is:
<PoketTourList numChild="21">
	<Country ID="12">
		<Range PriceFrom="0" PriceTo="100" Cnt="0"/>
		<Range PriceFrom="100" PriceTo="150" Cnt="0"/>
		<Range PriceFrom="150" PriceTo="200" Cnt="71"/>
		<Range PriceFrom="200" PriceTo="250" Cnt="376"/>
		<Range PriceFrom="250" PriceTo="300" Cnt="751"/>
		<Range PriceFrom="300" PriceTo="350" Cnt="684"/>
		<Range PriceFrom="350" PriceTo="400" Cnt="585"/>
		<Range PriceFrom="400" PriceTo="500" Cnt="1135"/>
		<Range PriceFrom="500" PriceTo="600" Cnt="787"/>
		<Range PriceFrom="600" PriceTo="700" Cnt="586"/>
		<Range PriceFrom="700" PriceTo="800" Cnt="461"/>
		<Range PriceFrom="800" PriceTo="1000" Cnt="485"/>
		<Range PriceFrom="1000" PriceTo="1200" Cnt="173"/>
		<Range PriceFrom="1200" PriceTo="1400" Cnt="86"/>
		<Range PriceFrom="1400" PriceTo="10000" Cnt="91"/>
	</Country>
	...
</PoketTourList>

Please, please, help me!

I'll try...


I don't think your English is bad, but your question is probably poorly stated. That said, I don't think any of the solutions proposed are the best for this problem. I am not very good at XSLT, so there might be syntactic errors but I hope it will send you in the right direction.

I would do something like:

<xsl:template match="/">
 <xsl:apply-templates select="PoketTourList/Country"/>
</xsl:template>

<xsl:template match="PoketTourList/Country">
 <xsl:apply-templates select="Range"/>
</xsl:template>

<xsl:template match="Range[value-of(@Cnt)&gt;value-of(./previous-sibling/@Cnt) and value-of(@Cnt)&lt;value-of(./next-sibling/@Cnt)]">

<!-- Here do what you want with the extrema's -->
<!-- Should match Range elements with @Cnt = 751,1135,485 but probably not @Cnt=91, see later -->
</xsl:template>


<xsl:template match="Range[not(value-of(@Cnt)&gt;value-of(./previous-sibling/@Cnt) and value-of(@Cnt)&lt;value-of(./next-sibling/@Cnt))]">

<!-- These are all the elements that are not extremas -->
<!-- Should match all other Range elements, probably including @Cnt=91 (last element). If you don't want the last, you should do something about this too -->
</xsl:template>


-------

The idea is to match the Range with an @Cnt value greater than the previous Range @Cnt and less than the next Range @Cnt value. In the other template I match those that do not satisfisfy both these conditions.

The syntax is most assuredly not correct and I have no idea what happens at the end points. You should probably make a third template that looks for position()=1 and only it's next sibling or position()=last() and only it's previous sibling.

Hope this helps and is more like what you want. At least here you have split up your elements in those whose @Cnt are local maxima and those whose are not.

Regards,
Ragulf Pickaxe :)

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. http://join.msn.com/?page=features/virus



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



Current Thread
  • RE: local extremums, (continued)
    • cknell - Tue, 18 Mar 2003 12:55:37 -0500 (EST)
    • Evgenia Firsova - Wed, 19 Mar 2003 01:13:31 -0500 (EST)
      • bix_xslt - Wed, 19 Mar 2003 02:37:44 -0500 (EST)
    • Ragulf Pickaxe - Wed, 19 Mar 2003 03:36:00 -0500 (EST) <=
    • Ragulf Pickaxe - Wed, 19 Mar 2003 04:27:25 -0500 (EST)
    • cknell - Wed, 19 Mar 2003 09:09:26 -0500 (EST)
      • TP - Wed, 19 Mar 2003 09:31:07 -0500 (EST)

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.