Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 25th, 2007, 06:32 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I don't know anything about your application architecture: you mention XSLT transformations, JSP, javascript, and user interaction, but I have no idea how all these things fit together. That makes it quite impossible to answer your question.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 26th, 2007, 02:08 AM
Registered User
 
Join Date: Oct 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Sorry for given a trouble to you.
  I would like to show the clear problem now

<root>
  <profile>
     <name>xyz<name>
     <salary>40000<salary>
     <addr>abc</addr>
 </profile>
 <profile>
    <name>mno<name
    <salary>50000<salary>
    <addr>def</addr>
  </profile>
</root>


 Using <xsl:value-of select="sum(root/profile/salary)"/> i can able to print total salaries in JSP.

 We have one submit button in that page. When the user clicks that button it will ask the confirmation "You are about to submit with a total payments of xxxx" by the onclick. Here xxxxx is the total of the salaries using (<xsl:value-of select="sum(root/profile/salary)"/>)

<a href="javascript:Click('/XMLFileUpload.do');" onclick="javascript:return confirmation(xxxx);"
                    title="Click to send to HMRC"><img src="sendtoHMRC.jpg" /> </a>



The total salaries is able to print in the JSP. I need to store that salary and pass as a argument to the java-script method invoked by onclick

<script>
function confirmation( xxxxx ){

if(!confirm(" You are about to submit with a total payments of"+ xxxx))
   return false;
     return true;
}

</script>






 
Old March 26th, 2007, 02:42 AM
Registered User
 
Join Date: Jan 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Use an attribute value template..

<xsl:variable name="total" select="sum(/root/profile/salary)" />
<a onclick="return confirmation({$total});"
...
...


 
Old April 16th, 2014, 02:51 AM
Registered User
 
Join Date: Apr 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default trying to sum and count the values

Hi Everyone. I am trying to get a total of the credits in one course. My xml file is :
<Handbook>
<courses>
<course_code></course_code>
<course_title></course_title>

<c_structure>
<course_info>
<year>1</year>
<semester>1</semester>

<units>
<unit>
<unit_code></unit_code>
<unit_title></unit_title>
<credit_points></credit_points>
</unit>

<unit>
<unit_code></unit_code>
<unit_title></unit_title>
<credit_points></credit_points>
</unit>
</units>
</course_info>


<course_info>
<year>1</year>
<semester>2</semester>

<units>
<unit>
<unit_code></unit_code>
<unit_title></unit_title>
<credit_points></credit_points>
</unit>

<unit>
<unit_code></unit_code>
<unit_title></unit_title>
<credit_points></credit_points>
</unit>
</units>
</course_info>

</c_structure>
</courses>
</Handbook>

and then another course starts

this is my xslt code to show the total number of credits of each course:
<h2><u>Student Results</u></h2>
xsl:for-each select="Handbook/courses[course_title=$sid]">

<strong>Course: </strong><xsl:value-of select="course_code"/><xsl:text>
</xsl:text><xsl:value-of select="course_title"/>

<Strong>Total CP: </strong><xsl:value-of select="sum(Handbook/c_structure/course_info/units/unit/credit_points)+(count(Handbook/c_structure/course_info/units/unit/credit_points))"/>


</xsl:for-each> <!-- This closes the Handbook for each loop -->

Because there are multiple courses in the handbook, so im trying to get the total credits of each courses summing up all the semester, say for example one course has three years with two semesters in each year, and there are multiple units in each semester. hope im not making it complex.
any help will be appericiated. as i am stuck at this point.


Thnks
 
Old April 16th, 2014, 03:30 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Please start a new thread for a new question rather than tagging onto a thread that was closed 7 years ago. And please say whether you are using XSLT 1.0 or 2.0.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old February 7th, 2017, 10:49 AM
Authorized User
 
Join Date: Feb 2017
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi,

<cac:InvoiceLine>
<cac:AllowanceCharge>
<cbc:SequenceNumeric>1</cbc:SequenceNumeric>
<cbc:Amount currencyID="TRY">2.00</cbc:Amount>
</cac:AllowanceCharge>
<cac:AllowanceCharge>
<cbc:SequenceNumeric>2</cbc:SequenceNumeric>
<cbc:Amount currencyID="TRY">3.00</cbc:Amount>
</cac:AllowanceCharge>
</cac:InvoiceLine>
<cac:InvoiceLine>
<cac:AllowanceCharge>
<cbc:SequenceNumeric>1</cbc:SequenceNumeric>
<cbc:Amount currencyID="TRY">4.00</cbc:Amount>
</cac:AllowanceCharge>
<cac:AllowanceCharge>
<cbc:SequenceNumeric>2</cbc:SequenceNumeric>
<cbc:Amount currencyID="TRY">5.00</cbc:Amount>
</cac:AllowanceCharge>
</cac:InvoiceLine>

xslt version 2.0

i want
if "SequenceNumeric=1" sum(cbc:Amount)
if "SequenceNumeric=2" sum(cbc:Amount)

how make this formul.

Thank you

Quote:
Originally Posted by mhkay View Post
The function sum() expects a node-set as its argument. You are supplying a single node (.), so sum() returns the numeric value of that node. You are then doing a string-concatenation of the results of several calls on the sum function.

You want <xsl:value-of select="sum(root/profile/salary)"/>



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 7th, 2017, 11:28 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sorry, but you are going to have to find a way to explain your requirements more clearly. Which SequenceNumeric? Which cbc:Amount? If you can't describe the logic, at least show what answer you expect for this input.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old February 7th, 2017, 11:35 AM
Authorized User
 
Join Date: Feb 2017
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Sorry, i want if SequenceNumeric value 1 total sum Amount



Quote:
Originally Posted by mhkay View Post
Sorry, but you are going to have to find a way to explain your requirements more clearly. Which SequenceNumeric? Which cbc:Amount? If you can't describe the logic, at least show what answer you expect for this input.
 
Old February 8th, 2017, 02:52 AM
Authorized User
 
Join Date: Feb 2017
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
Default

My aim is to collect the Amounts of those who have SequenceNumeric value 1

Quote:
Originally Posted by yozsubasi View Post
Sorry, i want if SequenceNumeric value 1 total sum Amount
 
Old February 8th, 2017, 06:14 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

That's a bit clearer (I hope). It sounds as if you want

Code:
sum(//cac:AllowanceCharge[cbc:SequenceNumeric='1']/cbc:Amount)
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
yozsubasi (February 8th, 2017)





Similar Threads
Thread Thread Starter Forum Replies Last Post
xslt adding text blitzer XSLT 3 May 19th, 2007 10:10 PM
xslt adding image palli2004 XSLT 2 December 30th, 2006 06:35 PM
adding elements in XSLT 1.0 spencer.clark XSLT 3 July 25th, 2005 09:41 AM
Adding Values NeilS21 Beginning VB 6 1 February 6th, 2004 10:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.