[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Sub total generation - filter problem
David (Carlisle),I agree it was verbose..here's the short form of it. I took out the sort statement , yet the same result. The input is sorted on bs_group, bs_categ. Thanks for letting me know it's also for beginners. Regards, XML: ========= <MyDataSet> <MyTable> <bs_group>Assets</bs_group> <bs_categ>01. Cash & Due from Banks</bs_categ> <curr_code>AUD</curr_code> <ps_download>487637.750</ps_download> </MyTable> <MyTable> <bs_group>Assets</bs_group> <bs_categ>01. Cash & Due from Banks</bs_categ> <curr_code>AUD</curr_code> <ps_download>-587788.493</ps_download> </MyTable> <MyTable> <bs_group>Assets</bs_group> <bs_categ>04.Loans</bs_categ> <curr_code>AUD</curr_code> <ps_download>93587.020</ps_download> </MyTable> <MyTable> <bs_group>Assets</bs_group> <bs_categ>04.Loans</bs_categ> <curr_code>AUD</curr_code> <ps_download>5802.950</ps_download> </MyTable> <MyTable> <bs_group>Assets</bs_group> <bs_categ>04.Loans</bs_categ> <curr_code>USD</curr_code> <ps_download>-742934.750</ps_download> </MyTable> </MyDataSet> XSLT:ONE: ========= <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:key name="key-group" match="MyTable" use="bs_group"/> <xsl:key name="key-group-bs_categ" match="MyTable" use="concat(bs_group,'+',bs_categ)"/> <xsl:template match="/"> <xsl:apply-templates select="MyDataSet" /> </xsl:template> <xsl:template match="MyDataSet"> <TABLE width='800px' > <TBODY> <xsl:apply-templates select="MyTable" > <xsl:sort select="0" data-type="text" order="ascending" /> </xsl:apply-templates> </TBODY> </TABLE> </xsl:template> <xsl:template match="MyTable"> <tr> <td > <xsl:value-of select="bs_group"/> </td> <td > <xsl:value-of select="bs_categ"/> </td> <td > <xsl:value-of select="curr_code"/> </td> <td > <xsl:value-of select="ps_download"/> </td> </tr> <!-- Categ total --> <xsl:if test="(following-sibling::MyTable[1]/bs_categ != bs_categ) or (following-sibling::MyTable[1]/bs_group != bs_group) or (position() = last())"> <xsl:variable name="ps_download_categ_sub_total" select="sum(key('key-group-bs_categ',concat(bs_group,'+',bs_categ))/ps_download)"></xsl:variable> <tr > <td colspan="3">Categ Total</td> <td align="right" > <xsl:value-of select="$ps_download_categ_sub_total"/> </td> </tr> </xsl:if> </xsl:template> </xsl:stylesheet> XSLT:TWO: ========= <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:key name="key-group" match="MyTable[curr_code='AUD']" use="bs_group"/> <xsl:key name="key-group-bs_categ" match="MyTable" use="concat(bs_group,'+',bs_categ)"/> <xsl:template match="/"> <xsl:apply-templates select="MyDataSet" /> </xsl:template> <xsl:template match="MyDataSet"> <TABLE width='800px' > <TBODY> <xsl:apply-templates select="MyTable[curr_code='AUD']" > <xsl:sort select="0" data-type="text" order="ascending" /> </xsl:apply-templates> </TBODY> </TABLE> </xsl:template> <xsl:template match="MyTable"> <tr> <td > <xsl:value-of select="bs_group"/> </td> <td > <xsl:value-of select="bs_categ"/> </td> <td > <xsl:value-of select="curr_code"/> </td> <td > <xsl:value-of select="ps_download"/> </td> </tr> <!-- Categ total --> <xsl:if test="(following-sibling::MyTable[1]/bs_categ != bs_categ) or (following-sibling::MyTable[1]/bs_group != bs_group) or (position() = last())"> <xsl:variable name="ps_download_categ_sub_total" select="sum(key('key-group-bs_categ',concat(bs_group,'+',bs_categ))/ps_download)"></xsl:variable> <tr > <td colspan="3">Categ Total</td> <td align="right" > <xsl:value-of select="$ps_download_categ_sub_total"/> </td> </tr> </xsl:if> </xsl:template> </xsl:stylesheet> -----Original Message----- From: David Carlisle [mailto:davidc@xxxxxxxxx] Sent: Thursday, December 16, 2004 12:18 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: Sub total generation - filter problem > I think I am NOT good enough to be in this list..but I NEED help. That's the whole point of the list, for begiiners to ask questions. However it helps if you make your question more intelligable. Basically I skipped over the question when you asked it as it's too big to comprehend (and if I can't see the answer, or can't see that it's interesting) then it gets left for someone else. You should put some work in to cutting down your xml input, do you really need 20 odd MyTable in order to show the problem similarly your stylesheet has lines <th id="bs_group" style="WIDTH:3%;" align='center' >BS Group </th> which scroll way off to the right and make it unreadable, you may need those attributes in your final result but you don't need them in a test case to ask a question to the group. I note that you have an xsl:sort on your apply-templates but within the templates you are testing following-sibling::MyTable[1] that's almost always the wrong thing to do the following-sibling relates to the original input not to the sorted order. David ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ ============================================================================== This message is for the sole use of the intended recipient. If you received this message in error please delete it and notify us. If this message was misdirected, CSFB does not waive any confidentiality or privilege. CSFB retains and monitors electronic communications sent through its network. Instructions transmitted over this system are not binding on CSFB until they are confirmed by us. Message transmission is not guaranteed to be secure. ==============================================================================
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|