[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] How to generate report using xslt


Subject: RE: [xsl] How to generate report using xslt
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 7 Feb 2005 10:30:38 -0000

So, you have an input something like

<table>
 <row>
   <a/>
   <b/>
   <price>23.00</price>
 </row>
 <row>
   <a/>
   <b/>
   <price>46.00</price>
 </row>
</table>

and you want the output to include the total price; but your stylesheet
knows nothing about the element names?

With a schema-aware XSLT 2.0 stylesheet you can achieve this as follows:

<xsl:template match="*">
  <!-- process each of the children, then: -->
  <xsl:for-each-group select="*/*" group-by="node-name(.)">  <!-- group the
grandchildren by name -->
    <xsl:if test="count(current-group()) gt 1 and 
                  every $x in current-group() satisfies $x instance of
element(*, xs:decimal)">
      <total for="{current-grouping-key()}">
         <xsl:value-of select="sum($x)"/>
      </total>
    </xsl:if>
  </xsl:for-each-group>
</xsl:template>

In practice, I don't think I would try to drive this entirely from the
schema type definitions. I think I would also set up some kind of
configuration file that says which elements you want to total, average, and
so on.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Sachin Raikar [mailto:sachin.raikar@xxxxxxxxx] 
> Sent: 07 February 2005 10:07
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] How to generate report using xslt
> 
> Hi One and All,
> 
> I am facing problems in generating reports.I have to create a generic
> xslt where any xml schema given as input should result in a report.
> 
> Till Now I am able to generate grid like report. But I want to show
> the total field also. The Total and sub total fields will be shown
> only if there are xml elements with integer/money/float data types.
> 
> Can anyone plz help me?
> 
> Sachin
> 
> -- 
> The key to happiness is having dreams; the key to sucess is making
> them come true


Current Thread