Q

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>
this.parentNode.parentNode.selectSingleNode
("./ctid").text;</xsl:eval>FDID<xsl:value-of 
select="./fabdatacontainer/fabdata/fdid" /></xsl:attribute>
					
  <xsl:attribute name="name">data<xsl:value-of 
select="./mmid" />CTID<xsl:eval>
this.parentNode.parentNode.selectSingleNode
("./ctid").text;</xsl:eval>FDID<xsl:value-of 
select="./fabdatacontainer/fabdata/fdid" /></xsl:attribute>
					
<xsl:attribute name="value"><xsl:value-of 
select="./fabdatacontainer/fabdata/fddata" /></xsl:attribute>					
</input>

<script type="text/javascript">			
	document.write(./fabdatacontainer/fabdata/fddata)
</script>
</font>
</td>	
</xsl:when>

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" 
version="1.0">

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">	
	document.write(./fabdatacontainer/fabdata/fddata)
</script>

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)") 
</script>

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 first published in September 2002

Dig deeper on XML and XML schema

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

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.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchSoftwareQuality

SearchCloudApplications

SearchAWS

TheServerSide

SearchWinDevelopment

Close