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

Conditional display of subtotal element

Subject: Conditional display of subtotal element
From: "FRIEDLAND, STEPHEN R" <STEPHEN_R_FRIEDLAND@xxxxxxxxx>
Date: Tue, 16 Apr 2002 16:22:25 -0400
conditional subtotal
Hi,
I've combined info from an archived thread to generate
subtotals and totals (thanks, Jeni). My problem now is
that there's a requirement for only the first date heading
for a subtotal to be shown. The first report listing is
what I'd like, the second is what I'm currently getting.
Following the report examples are the xml file and the
xsl. I'm looking for suggestions for how to show or not
show the date based on if it's the first one for this
grouping.

Thanks!
-Steve


Expected Version:
======================================================
Report
          04/01              LIB1M           40000000
                             LIBOR              25300
-----------------------------------------------------
                            total:           40025300

          04/02              LIBOR                130
                             LIB1M                550
                             EUR1B                390
-----------------------------------------------------
                            total:               1070

          04/03              LIB1M                 30
                             LIBOR                200
-----------------------------------------------------
                            total:                230

======================================================
Current Version:
======================================================
Report
          04/01              LIB1M           40000000
          04/01              LIBOR              25300
-----------------------------------------------------
                            total:           40025300

          04/02              LIBOR                130
          04/02              LIB1M                550
          04/02              EUR1B                390
-----------------------------------------------------
                            total:               1070

          04/03              LIB1M                 30
          04/03              LIBOR                200
-----------------------------------------------------
                            total:                230
======================================================
<?xml version="1.0" encoding="UTF-8"?>
<table header="test">
	<row>
		<TRADE_ID>71701FB</TRADE_ID>
		<NTL>25000000</NTL>
		<INDEX>LIB1M</INDEX>
		<RESET_DATE>04/01</RESET_DATE>
	</row>
	<row>
		<TRADE_ID>71402FB</TRADE_ID>
		<NTL>15000000.00</NTL>
		<INDEX>LIB1M</INDEX>
		<RESET_DATE>04/01</RESET_DATE>
	</row>
	<row>
		<TRADE_ID>71703FB</TRADE_ID>
		<NTL>22000.00</NTL>
		<INDEX>LIBOR</INDEX>
		<RESET_DATE>04/01</RESET_DATE>
	</row>
	<row>
		<TRADE_ID>71704FB</TRADE_ID>
		<NTL>3300.00</NTL>
		<INDEX>LIBOR</INDEX>
		<RESET_DATE>04/01</RESET_DATE>
	</row>
	<row>
		<TRADE_ID>64505US</TRADE_ID>
		<NTL>100.00</NTL>
		<INDEX>LIBOR</INDEX>
		<RESET_DATE>04/02</RESET_DATE>
	</row>
	<row>
		<TRADE_ID>64506US</TRADE_ID>
		<NTL>30.00</NTL>
		<INDEX>LIBOR</INDEX>
		<RESET_DATE>04/02</RESET_DATE>
	</row>
	<row>
		<TRADE_ID>64507US</TRADE_ID>
		<NTL>220.00</NTL>
		<INDEX>LIB1M</INDEX>
		<RESET_DATE>04/02</RESET_DATE>
	</row>
	<row>
		<TRADE_ID>64508US</TRADE_ID>
		<NTL>330.00</NTL>
		<INDEX>LIB1M</INDEX>
		<RESET_DATE>04/02</RESET_DATE>
	</row>
	<row>
		<TRADE_ID>64509US</TRADE_ID>
		<NTL>390.00</NTL>
		<INDEX>EUR1B</INDEX>
		<RESET_DATE>04/02</RESET_DATE>
	</row>
	<row>
		<TRADE_ID>60610US</TRADE_ID>
		<NTL>30.00</NTL>
		<INDEX>LIB1M</INDEX>
		<RESET_DATE>04/03</RESET_DATE>
	</row>
	<row>
		<TRADE_ID>70811FB</TRADE_ID>
		<NTL>200.00</NTL>
		<INDEX>LIBOR</INDEX>
		<RESET_DATE>04/03</RESET_DATE>
	</row>
</table>

======================================================
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" />
<xsl:strip-space elements="*"/>

<xsl:variable name="newline">
  <xsl:text>&#10;&#13;</xsl:text>
</xsl:variable>
<xsl:variable name="spacer">
  <xsl:text disable-output-escaping="yes">    </xsl:text>
</xsl:variable>
<xsl:variable name="colspacer">
  <xsl:text disable-output-escaping="yes">               </xsl:text>
</xsl:variable>
<xsl:variable name="colwidth">
  <xsl:text>15</xsl:text>
</xsl:variable>
<xsl:variable name="underline">
  <xsl:text>-----------------------------------------------------</xsl:text>
</xsl:variable>

<xsl:key name="rows-by-rdate" match="row" use="RESET_DATE"/>
<xsl:key name="rows-by-rdate-and-index" match="row"
use="concat(RESET_DATE,'+',INDEX)"/>

<xsl:template match="/">
  <xsl:apply-templates />
</xsl:template>

<xsl:template match="table">
  <xsl:text>Report</xsl:text><xsl:value-of select="$newline"/>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="row">
	 <!-- Generate a subtotal row -->
	 <xsl:if test="following-sibling::row[1]/INDEX != INDEX or
following-sibling::row[1]/RESET_DATE != RESET_DATE or position() = last()">
		<!--xsl:choose>
			<xsl:when test="a test to decide if date should be
shown"-->		
		<xsl:call-template name="padValues">
			<xsl:with-param name="value" select="RESET_DATE"/>
			<xsl:with-param name="length" select="$colwidth"/>
		</xsl:call-template>
			<!--/xsl:when>	
			<xsl:otherwise>	
			  	<xsl:value-of select="$colspacer"/>
			</xsl:otherwise>	
		</xsl:choose-->
	  	<xsl:value-of select="$spacer"/>
	  		  	
		<xsl:call-template name="padValues">
			<xsl:with-param name="value" select="INDEX"/>
			<xsl:with-param name="length" select="$colwidth"/>
		</xsl:call-template>
	  	<xsl:value-of select="$spacer"/>

		<xsl:call-template name="padValues">
			<xsl:with-param name="value"
select="sum(key('rows-by-rdate-and-index',concat(RESET_DATE,'+',INDEX))/NTL)
"/>
			<xsl:with-param name="length" select="$colwidth"/>
		</xsl:call-template>  		

  		<xsl:value-of select="$newline"/>  		
  	</xsl:if>

	 <!-- Generate a total row -->
  	<xsl:if test="following-sibling::row[1]/RESET_DATE != RESET_DATE or
position() = last()">
  		<xsl:value-of select="$underline"/>  		
  		<xsl:value-of select="$newline"/>  		
		<xsl:value-of select="$colspacer"/>
		<xsl:value-of select="$spacer"/>
		<xsl:call-template name="padValues">
			<xsl:with-param name="value">total:</xsl:with-param>
			<xsl:with-param name="length" select="$colwidth"/>
		</xsl:call-template>
		<xsl:value-of select="$spacer"/>

		<xsl:call-template name="padValues">
			<xsl:with-param name="value"
select="sum(key('rows-by-rdate',RESET_DATE)/NTL)"/>
			<xsl:with-param name="length" select="$colwidth"/>
		</xsl:call-template>  		

	  	<xsl:value-of select="$newline"/>
	  	<xsl:value-of select="$newline"/>
	  		  	
  	</xsl:if>
  
</xsl:template>

<!-- Create fixed length string left padded -->
<xsl:template name="padValues">
	<xsl:param name="value"/>
	<xsl:param name="length"/>
	
	<xsl:if test="string-length($value) = $length">
  		<xsl:value-of select="$value"/>
	</xsl:if>
	<xsl:if test="string-length($value) &lt; $length">
  		<xsl:text> </xsl:text>
		<xsl:call-template name="padValues">
			<xsl:with-param name="value" select="$value"/>
			<xsl:with-param name="length" select="$length - 1"/>
		</xsl:call-template>
	</xsl:if>
</xsl:template>

</xsl:stylesheet>
======================================================


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.