[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

XSL Column Totals

Posted on 2004-10-20
7
Medium Priority
?
479 Views
Last Modified: 2008-02-01
I am writing a reporting procedure for a web based adminstration system database data is returned as xml shown below - i wish to add totals to the bottom of each column. i want this to work for any recordset that i give it so column headings are unknown in advance.

i can use

<xsl:variable name="total" select="concat('/xml/row/',name())" /><xsl:variable name="current" select="concat('/xml/row/',name())" />

to get the full path to each column  as a string

however

<xsl:value-of select="sum($total)" />

gives me an error (expression does not return a dom node)

putting the value in directly as below does work

<xsl:value-of select="sum(/xml/row/MortgageRequired)" )/>


any suggestions?

<xml>
<row>
<submitted sorttype="135">18/08/04 12:22:57</submitted>
<IntroducerEmail sorttype="200">david@emailaddress.co.uk</IntroducerEmail>
<PurchasePrice sorttype="6">100000</PurchasePrice>
<MortgageRequired sorttype="6">90000</MortgageRequired>
<LTV sorttype="131">90</LTV>
</row>
<row>
<submitted sorttype="135">18/08/04 12:22:57</submitted>
<IntroducerEmail sorttype="200">test@emailaddress.co.uk</IntroducerEmail>
<PurchasePrice sorttype="6">175000</PurchasePrice>
<MortgageRequired sorttype="6">100000</MortgageRequired>
<LTV sorttype="131">57</LTV>
</row>
</xml>



0
Comment
Question by:steve_steele
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 12357430
<xsl:for-each select="xml/row">
<TR>
<TD>
   <xsl:value-of select="sum(MortgageRequired)" )/>
</TD>
</TR>
</xsl:for-each>
0
 
LVL 35

Expert Comment

by:YZlat
ID: 12357557
<?xml version="1.0" encoding="UTF-8" ?>

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

<xsl:template match="/">
<TABLE>
<TR>
                  <TD width="35%">Date Submitted</TD>
            <TD width="20%">E-Mail</TD>
            <TD>total1</TD>
            <TD width="20%">total2</TD>
            <TD>LTV</TD>
         </TR>
 <xsl:for-each select="xml/row">
         <TR STYLE="font-family:Verdana; font-size:8pt;color:darkred; padding:0px 2px">
                  <TD>
                        <xsl:value-of select="submitted" />
                  </TD>
                  <TD>
                        <a href="mailto:{link}"><xsl:value-of select="IntroducerEmail" /></a>
                  </TD>
                  <TD>
                        <xsl:value-of select="PurchasePrice" />
                  </TD>
                  <TD>
                        <xsl:value-of select="MortgageRequired" />
                  </TD>  
                  <TD>
                        <xsl:value-of select="LTV" />
                  </TD>      
            </TR>
            </xsl:for-each>
<TR>
<TD></TD>
<TD></TD>
<TD></TD>
<TD><xsl:value-of select="sum(MortgageRequired)"/></TD>
<TD></TD>
</TR>
 </TABLE>
</xsl:template>
</xsl:stylesheet>
0
 

Author Comment

by:steve_steele
ID: 12357626
Cant do either of those as i'm trying to get it it work without knowing the column headings in advance

ie the same xsl would still work for

<xml>
<row>
<somthingelse sorttype="135">18/08/04 12:22:57</somthingelse >
<wovvit sorttype="200">david@emailaddress.co.uk</wovvit >
<gagglepin sorttype="6">100000</gagglepin >
</row>
<row>
<somthingelse sorttype="135">18/08/04 12:22:57</somthingelse >
<wovvit sorttype="200">test@emailaddress.co.uk</wovvit >
<gagglepin sorttype="6">4545454</gagglepin >
</row>
</xml>
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 7

Expert Comment

by:J_Mak
ID: 12357903
Try this variable:

<xsl:variable name="total" select="//row/node()"/>

The problem with yours is that the path /xml/row/name() is that name() is not a node.... it is a string. That's why it complains about no dom node being returned. Try my solution. It hasn't yet been tested but it should give the current node, that is the context node and all others in the following <row> elements. Cheers.

Btw, if that doesn't work, try:

<xsl:variable name="total" select="//row/self::node()"/>
0
 
LVL 7

Expert Comment

by:J_Mak
ID: 12357943
Or even try this:

<xsl:variable name="total" select="//row/."/>

I'm not sure if that'll work. It may need some polishiing up.
0
 
LVL 26

Accepted Solution

by:
rdcpro earned 2000 total points
ID: 12362515
Well, this "works" but of course It assumes sorttype=6 means you want the column summed.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
      <xsl:template match="xml">
            <table cellpadding="4px">
                  <tr>
                        <th><xsl:text> </xsl:text></th>
                        <xsl:for-each select="row[1]/*">
                              <th><xsl:value-of select="local-name()"/></th>
                        </xsl:for-each>
                  </tr>
                  <xsl:for-each select="row">
                        <tr>
                              <th><xsl:text> </xsl:text></th>
                              <xsl:for-each select="*">
                                    <td align="center"><xsl:value-of select="."/></td>
                              </xsl:for-each>
                        </tr>
                  </xsl:for-each>
                  <tr>
                        <th>Total:</th>
                        <xsl:for-each select="row[1]/*">
                              <xsl:variable name="vPosition" select="position()"/>
                              <th>
                                    <xsl:if test="@sorttype = 6">
                                          <xsl:value-of select="sum(/xml/row/*[$vPosition])"/>
                                    </xsl:if>
                              </th>
                        </xsl:for-each>
                  </tr>
            
            </table>
      </xsl:template>
</xsl:stylesheet>


Regards,
Mike Sharp
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 12362520
BTW:  the output of the above XSLT is:

<table cellpadding="4px">
      <tr>
            <th> </th>
            <th>submitted</th>
            <th>IntroducerEmail</th>
            <th>PurchasePrice</th>
            <th>MortgageRequired</th>
            <th>LTV</th>
      </tr>
      <tr>
            <th> </th>
            <td align="center">18/08/04 12:22:57</td>
            <td align="center">david@emailaddress.co.uk</td>
            <td align="center">100000</td>
            <td align="center">90000</td>
            <td align="center">90</td>
      </tr>
      <tr>
            <th> </th>
            <td align="center">18/08/04 12:22:57</td>
            <td align="center">test@emailaddress.co.uk</td>
            <td align="center">175000</td>
            <td align="center">100000</td>
            <td align="center">57</td>
      </tr>
      <tr>
            <th>Total:</th>
            <th/>
            <th/>
            <th>275000</th>
            <th>190000</th>
            <th/>
      </tr>
</table>

Regards,
Mike Sharp
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question