Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: stumped on XSL tranformation to produce normalized bar graph [Thread Next] Re: stumped on XSL tranformation to produce normalized bar graphTo: 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
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
