This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: find first occurrence of attribute value grouped by element


>
> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]