Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: stumped on XSL tranformation to produce normalized bar graph

From: Thomas V <thomas@-------.--->
To: NULL
Date: 6/26/2009 12:10:00 AM
On Jun 23, 11:46=A0am, Thomas V <tho...@badsoda.com> wrote:
> On Jun 22, 10:56=A0pm, Thomas V <tho...@badsoda.com> wrote:
>
>
>
> > Hi,
>
> > I'm new to XSL and have been given an assignment which has me stumed.
> > I'm hoping you could assist. I've been given a set of XML data (see
> > format below) and have been asked to produce a normalized bar grap in
> > html for output.
>
> > <xml>
> > =A0 <rs:data>
> > =A0 =A0<z:row class=3D'book' title=3D'nice book' status=3D'open' />
> > =A0 =A0<z:row class=3D'book' title=3D'good book' status=3D'closed' />
> > =A0 =A0<z:row class=3D'book' title=3D'aweful book' status=3D'closed' />
> > =A0 =A0<z:row class=3D'vase' title=3D'blue vase' status=3D'open' />
> > =A0 =A0<z:row class=3D'vase' title=3D'red vase' status=3D'closed' />
> > =A0 =A0<z:row class=3D'vase' title=3D'green vase' status=3D'open' />
> > =A0 </rs:data>
> > </xml>
>
> > The idea would be to have for each data row grouped per class and the
> > relative number of statuses computed.
>
> > Based on the above input the expected output would be as follows.
>
> > <table>
> > =A0 <tr><th>class</th><th span=3D2>graph</th></tr>
> > =A0 <tr><td>book</th><td width=3D'33%'>open<td><td width=3D'67%'>closed=
<td></
> > tr>
> > =A0 <tr><td>vase</th><td width=3D'33%'>open<td><td width=3D'67%'>closed=
<td></
> > tr>
> > </table>
>
> > It should be noted that the number of different values the status
> > attribute can take can vary (ie. it can be more than just open an
> > closed as in the example above).
>
> > If you feel writing up XSL for this is trivial then your help would be
> > greatly appreciated.
> > - Thomas
>
> Hi again,
>
> I've made some progress on the issue grouping the items using the
> Muenchian method. My xsl template now looks something like
>
> <xsl:stylesheet
> =A0 xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
> =A0 xmlns:rs=3D'urn:schemas-microsoft-com:rowset'
> =A0 xmlns:z=3D'#RowsetSchema'
> =A0 version=3D"2.0">
> <xsl:key name=3D"issues-class" match=3D"z:row" use=3D"@class" />
> <xsl:template match=3D"rs:data">
> =A0 <xsl:for-each select=3D"z:row[count(. | key('issues-class', @class)
> [1]) =3D 1]">
> =A0 =A0 <xsl:sort select=3D"@class" />
> =A0 =A0 <xsl:value-of select=3D"substring-after(@class,'string;#')" />
> =A0 =A0 <xsl:for-each select=3D"key('issues-class', @class)">
> =A0 =A0 =A0 <xsl:sort select=3D"@title" />
> =A0 =A0 =A0 <xsl:value-of select=3D"substring-after(@title,'string;#')" /=
><xsl:value-of select=3D"@status" />
>
> =A0 =A0 </xsl:for-each>
> =A0 </xsl:for-each>
> </xsl:template>
> </xsl:stylesheet>
>
> Now what I'd need to achieve is to:
> - calculate how many records there are of each 'class' attribute
> - for each 'class' calculate how many records there are of each
> 'status' attribute
> - calculate the relative representation (percentage) each status
> within a given class
>
> With that I should be in a position to produce a table or a bar graph.
>
> Again, if anyone out there can help it would be greatly appreciated.
>
> -Thomas

I've been able to solve the riddle.

I needed 2 keys: one for the first loop though the 'class' attribute
then another based on a concatenation of the 'class' and the 'status'.
With those keys defined and applying the muenchian technique to loop
through the records it was a piece of cake to get the counts and do
the necessary math.

Considering how simple this turned out to be I'm a little disappointed
no one offered to point me in the right direction though. Is there
some etiquette I broke when asking the question?

Rgds,
-Thomas


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent