Problem solve Get help with specific problems with your technologies, process and projects.

How can I assign my attribute value to a parameter to solve this sum problem?

I have <xsl:attribute> in my xsl code which looks like:

<xsl:when test=".[mmisnumber $ieq$ 'True']">	

<td width="200" align="center">
  <xsl:attribute name="class">bglightgrey</xsl:attribute>
  <font size="2">
  <input type="text" size="10" onkeyup="javascript: forceNumeric(this);">
  <xsl:attribute name="id">data<xsl:value-of 
select="./mmid" />CTID<xsl:eval>
select="./fabdatacontainer/fabdata/fdid" /></xsl:attribute>
  <xsl:attribute name="name">data<xsl:value-of 
select="./mmid" />CTID<xsl:eval>
select="./fabdatacontainer/fabdata/fdid" /></xsl:attribute>
<xsl:attribute name="value"><xsl:value-of 
select="./fabdatacontainer/fabdata/fddata" /></xsl:attribute>					

<script type="text/javascript">			

My problem is I need to sum up the last attribute, <xsl:attribute name="value">. The sum should exclude the first node. For instance, if there are 3 values returned, the sum should include value2 and value3. I tried using sum:


But I get an error "unknown method" I guess this is because I use an outdated xml declaration and run it using IE 6.0:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

The correct ones should be:

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

Note: If I changed to the updated declaration, my existing page won't appear at all.

So to solve the sum problem, I need to do it in Javascript. But I'm not sure how to assign the attribute value to a parameter. I know there is a way because when I add this script in my code, I can see the output of the attribute appear on the browser, which looks like
777 888 999 (for this output, I need to sum up 888+999)

<script type="text/javascript">	

I saw this online, but it doesn't seem to work with my existing code:

<script type="text/javascript">	
	var totalVal = xmlToSum.selectSingleNode("sum(//@value)") 

Client-side XSLT is notororiously platform specific for any non-trivial processing. If you can pre-process the XML on the server-side to differentiate the first value from subsequent ones, then the sum function will be more straightforward.
This was last published in September 2002

Dig Deeper on Development implications of microservices architecture



Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.