[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: Filtering Numeric Output with Changing Parameter
Subject: Re: Filtering Numeric Output with Changing Parameter
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Sat, 20 Jul 2002 02:50:22 +0200
|
Hello Tim,
the stylesheet is relative simple as you can see. You only have to
process the nodes step by step:
(added a <root> element in in- and output)
<xsl:template match="root">
<root>
<xsl:apply-templates select="stock[1]"/>
</root>
</xsl:template>
<xsl:template match="stock">
<xsl:variable name="threshold" select="1"/>
<xsl:copy-of select="."/>
<xsl:apply-templates select="following-sibling::stock
[price >= current()/price + $threshold
or price <= current()/price - $threshold][1]"/>
</xsl:template>
The first stock must be selected. The next stock, that shell be
selected, is either "price >= current()/price + $threshold" or "price <=
current()/price - $threshold", again we will only have the first one,
that fulfills one of both conditions.
I declared $threshold as variable, you can use it hard-coded in the
expression or as parameter too.
Regards,
Joerg
Tim Lewis wrote:
I'd like to take a pile of numeric data and filter it down to a smaller
pile by selecting for output only values that change by more than a
threshold amount from the beginning value. If a value gets selected for
output, then the next output value would have to be different from it by
more than the threshold. For example, say I have a pile of stock price
data and I want to plot only values that change by more than 1.00. If
the first value is 27.50, then I want to look through the data and
ignore it until I find a price >= 28.50 or <= 26.50. If I find a price
of 28.50, then I want to continue my search, but now I am looking for
prices >= 29.50 or <= 27.50.
So given:
<stock>
<time>0.0</time>
<price>27.50</price>
</stock>
<stock>
<time>1.0</time>
<price>27.75</price>
</stock>
<stock>
<time>3.0</time>
<price>27.20</price>
</stock>
<stock>
<time>4.0</time>
<price>28.50</price>
</stock>
<stock>
<time>5.0</time>
<price>28.25</price>
</stock>
<stock>
<time>6.0</time>
<price>27.75</price>
</stock>
<stock>
<time>7.0</time>
<price>27.80</price>
</stock>
<stock>
<time>8.0</time>
<price>25.50</price>
</stock>
I want:
<stock>
<time>0.0</time>
<price>27.50</price>
</stock>
<stock>
<time>4.0</time>
<price>28.50</price>
</stock>
<stock>
<time>8.0</time>
<price>25.50</price>
</stock>
I understand that I cannot use a for-each loop because the value of my
comparison "variables" needs to be variable. I also understand that I
need to use recursion to do it. However, I struggle mightily with
procedural programming, so functional programming and recursion chew me
up and spit me out.
Any guidance would be appreciated. An actual named template to get this
job done would be even more wondeful!
TIA,
Tim Lewis
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|