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

RE: find first occurrence of attribute value grouped b

Subject: RE: find first occurrence of attribute value grouped by element
From: "James Fuller" <james.fuller@xxxxxxxxxx>
Date: Mon, 23 Sep 2002 16:43:26 +0100
xpath find first
>
> Hi,
>
> This is my first posting to this list site. I have tried to search the
> archives
> and other sites to help with my problem, but have not found anything
> which addresses it specifically.  Please excuse my newbieness.
>
>
> Problem:
>
> Determine the first occurrence of a particular attribute value grouped by
> element.
>
>
> Example data:
>
> testdata.xml:
>
> <?xml version="1.0" ?>
> <!-- simplified test data example 1-->
> <root>
> <testdata Unit_id="000001">
>  <test id="test1" passed='F' timestamp="2002-09-01 12:00:00"></test>
>  <test id="test2" passed='T' timestamp="2002-09-01 13:00:00"></test>
>  <test id="test1" passed='T' timestamp="2002-09-02 11:00:00"></test>
> </testdata>
> <testdata Unit_id="000002">
>  <test id="test1" passed='T' timestamp="2002-09-01 10:00:00"></test>
>  <test id="test2" passed='T' timestamp="2002-09-01 13:00:00"></test>
>  <test id="test3" passed='T' timestamp="2002-09-02 11:00:00"></test>
> </testdata>
> <testdata Unit_id="000003">
>  <test id="test1" passed='T' timestamp="2002-09-03 10:00:00"></test>
>  <test id="test3" passed='T' timestamp="2002-09-04 14:00:00"></test>
>  <test id="test2" passed='F' timestamp="2002-09-02 11:00:00"></test>
> </testdata>
> </root>
>
>
> Desired output:
> ------------------------------------------------------------------
> ----------
> ----------------
> Test     Total Attempts   Total Pass  Total Fail   Pass on First Attempt
> First Run Ratio
> ------------------------------------------------------------------
> ----------
> ----------------
> test 1        4              3           1                   2
> 66.7%
> test 2        4              2           2                   1
> 25%
> test 3        2              2           0                   2
> 100%
>

Hello John,

without really going into your code, you could vastly simplify your code by
applying a 2 stage transformation. Yes, it is good to use keys, but you may
find it easier to do something simple then optimise with keys later.

I would suggest regrouping your data first ( though of course this process
could be physical or just in memory....you may have constraints due to the
size of data your are handling ),and maybe you have avoided this because you
havent taken on board node-set() function ? but of course this might be
because of processing constraints

consider a template approach

<xsl:apply-templates select="testdata/test">
<xsl:sort select="@timestamp"/>
</xsl:apply-templates>

will match each test and sort based on timestamp which means you could
create a 1st copy of your data, which is just

<root>
<test/>
.
.
.
</root>

easier to manipulate this no ?

an easier way could be storing this in a variable for further processing...

<xsl:variable name="holdresult" select="//test"/> a general comment, try not
to use // in your XPATH's, as I am doing here ( and you are in your code )
try to explicitly create absolute paths...your transforms will run much
quicker, and you will understand what is going on better.

ok, now you can use $holdresult and do stuff with it ( of course you may
also have to use node-set() extension to transform the RTF back into a node
...if you need to seriousely manipulate ).

wish I had more time to go through your code;  organise and manipulate your
data first, worry about printing out in a table later.

gl, jim fuller



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


Current Thread

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.