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

RE: local extremums

Subject: RE: local extremums
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Wed, 19 Mar 2003 12:22:39 -0600
les extremums
Ragulf wrote:

> If there is something wrong with this code, I would like to 
> hear it myself.
>
> <xsl:template
>   match="Range[number(@Cnt)&gt;number(./previous-sibling/@Cnt) and
>   number(@Cnt)&lt;value-of(./next-sibling/@Cnt)]">
>   <xsl:call-template name="IsLocalMaximum"/>
> </xsl:template>
> 
> <xsl:template
>   match="Range[not(number(@Cnt)&gt;number(./previous-sibling/@Cnt)
>   and number(@Cnt)&lt;value-of(./next-sibling/@Cnt))]">
>   <xsl:choose>
>   [snip...]

A few comments...

1) Since you're looking for local maxima, I think that instead
 of Cnt1 > Cnt0 and Cnt1 < Cnt2 (pardon my simplified references),
 you want Cnt1 > Cnt0 and Cnt1 > Cnt2 (note the second comparison
 changes the < to >).  In other words you want to match Range elements
 whose @Cnt is greater than that of both its adjacent siblings, not
 between them.

2) A style/maintainability/performance issue...
 Since the second template matches every Range element not matched
 by the first, you don't need to include that huge complex [not(...)]
 predicate.
 Just use <xsl:template match="Range">, which will by default have
 a lower priority than the first template, and will "catch" every
 Range element the first one doesn't match.

3) "previous-sibling", without the ::, means "a child element named
  'previous-sibling'".  Obviously this isn't what you want.
  Also, the axis is called preceding-sibling::.
  I would rework your match pattern as:
   
    match="Range[@Cnt &gt; preceding-sibling::Range[1]/@Cnt and
                 @Cnt &gt; following-sibling::Range[1]/@Cnt]"

(Note, number() is not really necessary as the < > operators convert
their operands to numbers; all number() does here is make sure that
only the *first*node* of its argument is considered.  I used [1]
to take care of that aspect since it's clearer.)


Evgenia, here's a stylesheet that I think does what you want.
It outputs a table showing each Range as a row, with three columns
for the three attributes.  The Ranges are in document order.
Each Range that is a local maximum (i.e. @Cnt is greater than that of
the row immediately before or after) is styled in bold.
I treated first and last Range elements as local maxima if
they were greater than their only adjacent sibling.
The table is divided into countries with a row-wide "Country {@ID}"
cell.

Hopefully this is the kind of thing you were looking for...

Blessings,
Lars



<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:template match="/">
    <html>
      <head>
        <style type="text/css">
          .localmax {
             font-weight: bold;
          }

          td {
             text-align: right;
          }
        </style>
      </head>
      <body>
        <xsl:apply-templates select="PoketTourList"/>
      </body>
    </html>
  </xsl:template>

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

  <xsl:template match="Country">
    <tr><th colspan="3">Country <xsl:value-of select="@ID" /></th></tr>
    <tr>
      <th>@PriceFrom</th>
      <th>@PriceTo</th>
      <th>@Cnt</th>
    </tr>
    <xsl:apply-templates select="Range" />
  </xsl:template>

  <xsl:template match="Range">
    <xsl:variable name="IsLocalMax"
      select="(position() = 1 or @Cnt &gt; preceding-sibling::Range[1]/@Cnt)
              and (position() = last()
                   or @Cnt &gt; following-sibling::Range[1]/@Cnt)" />
    <tr>
      <xsl:if test="$IsLocalMax">
        <xsl:attribute name="class">localmax</xsl:attribute>
      </xsl:if>
      <td><xsl:value-of select="@PriceFrom" /></td>
      <td><xsl:value-of select="@PriceTo" /></td>
      <td><xsl:value-of select="@Cnt" /></td>
    </tr>
  </xsl:template>

</xsl:stylesheet>


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


Current Thread
  • RE: local extremums, (continued)
    • 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)
      • Lars Huttar - Wed, 19 Mar 2003 13:19:50 -0500 (EST) <=
    • cknell - Wed, 19 Mar 2003 09:09:26 -0500 (EST)
      • TP - Wed, 19 Mar 2003 09:31:07 -0500 (EST)
        • TP - Wed, 19 Mar 2003 09:54:17 -0500 (EST)
    • David . Pawson - Wed, 19 Mar 2003 09:53:55 -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.