A question on detecting a simple trend using XSL

I have a percent value which, if it drops over time, indicates an upstream problem for that dealer. Every few days, I run a query to capture these numbers. I'm looking for a way to spot

percents that have dropped over, say, the last n entries. I'm not necessarily interested in an absolute drop from start date to end date, I'm most interested in detecting a downward trend.

There are about 350 dealers to track, and this will rise to about 2000.

This snapshot data is not being captured in any table.

So if I have a dealer whose percent drops over time, as in this example, I want to spot it:

9/27 dealer X 46% <-- 3
9/27 dealer Y 97%
9/25 dealer X 52% <-- 2
9/25 dealer Y 98%
9/22 dealer X 57% <-- 1
9/22 dealer Y 96%


If I capture each day's snapshot as xml, like this

<snapshot date="20130927">
      <dealer number="3887" pct="46"/>
      <dealer number="18054" pct="97"/>
      <dealer number="9999" pct="88"/>
</snapshot>
<snapshot date="20130925">
      <dealer number="3887" pct="52"/>
      <dealer number="18054" pct="98"/>
</snapshot>
<snapshot date="20130922">
      <dealer number="3887" pct="57"/>
      <dealer number="18054" pct="96"/>
</snapshot>
...

can I then use XSL to identify the downward-trending dealer 3887?

A twist to this is that new dealers are coming on, so not every dealer will be in every snapshot. So in the example above, dealer 9999 first appears on 9/27.

Is it possible to use XSL to turn the example above into something like this?

<html>
      <body>
      <table>
      <tbody>
      <tr>
            <td>dealer</td><td>9/22</td><td>9/25</td><td>9/27</td>
      </tr>
      <tr>
            <td>18054</td><td>96</td><td>98</td><td>97</td>
      </tr>
      <tr>
            <td>3887</td><td>57</td><td>52</td><td>46</td>
      </tr>
      <tr>
            <td>9999</td><td></td><td></td><td>88</td>
      </tr>
      </tbody>
      </table>
      </body>
</html>

To be clear, I don't especially care what the output looks like as long as I can identify the dealers whose percent has been dropping.
FelineConspiracyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
This XSLT will give you the table

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    
    <xsl:key name="dealer-no" match="dealer" use="@number"/>
    <xsl:key name="dealer-no-dt" match="dealer" use="concat(parent::snapshot/@date, '-', @number)"/>
    
    <xsl:template match="/">
        <xsl:variable name="root" select="."/>
        <html>
            <body>
                <table>
                    <tbody>
                        <tr>
                            <th>dealer</th>
                            <xsl:for-each select="$root//snapshot">
                                <xsl:sort select="@date" order="ascending" data-type="text"/>
                                <th>
                                    <xsl:value-of select="number(substring(@date, 5, 2 ))"/>
                                    <xsl:text>/</xsl:text>
                                    <xsl:value-of select="number(substring(@date, 7, 2 ))"/>
                                </th>
                            </xsl:for-each>
                        </tr>
                        <xsl:for-each select=".//dealer[generate-id() = generate-id(key('dealer-no', @number)[1])]">
                            <xsl:variable name="this-dealer" select="."/>
                            <tr>
                                <th><xsl:value-of select="@number"/></th>
                                <xsl:for-each select="$root//snapshot">
                                    <xsl:sort select="@date" order="ascending" data-type="text"/>
                                    <td>
                                        <xsl:value-of select="key('dealer-no-dt',concat(@date, '-', $this-dealer/@number))/@pct"/>
                                    </td>
                                </xsl:for-each>
                            </tr>
                        </xsl:for-each>
                    </tbody>
                </table>
            </body>
        </html>        
    </xsl:template>
    
</xsl:stylesheet>

Open in new window

0
Geert BormansInformation ArchitectCommented:
it visualizes downward trending because you can view in a table.
If you gave me an algoritm for calculating downward trending, I could give the rows with a downward trend a red coloured background...

But that would mean a second pass, likely and why use XST for something it is not usefull for?

Here is what I would do.
Save the html table with a .xls extension.
if you have excel installed, import in excel... the html table will seamlessly be imported in excel
use some statistacal functionality from excel to report on the trends
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FelineConspiracyAuthor Commented:
Thank you! My idea is probably a lousy one, but at any rate I'll brush up on my XSL.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.