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

RE: How to generate report using xslt

Subject: RE: How to generate report using xslt
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 7 Feb 2005 10:30:38 -0000
generate report from xml
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:  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

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.