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 17th, 2011, 05:37 AM
Registered User
 
Join Date: Feb 2011
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Default How to sum if we have multi condition?

Hi all,
i have to sum elements in fields which are in substring(field[@id='0'], 9,2). But where is some condition I should to check if substring(field[@id='0'], 1,3)='MAR' and substring(field[@id='0'],12,4)='0010'). so of my example we should get answer '25'.

Code:
<document>
	<line id="0">
		<field id="0"><![CDATA[MAR6477 11 0010]]></field>
	</line>
	<line id="1">
		<field id="0"><![CDATA[MAR6477 12 0020]]></field>
	</line>
	<line id="2">
		<field id="0"><![CDATA[MAR6477 14 0010]]></field>
	</line>
</document>
What is the simplest decision to sum it?
 
Old March 17th, 2011, 05:54 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Summing over computed values in XSLT 2.0 is easy, for example

Code:
sum(for $x in line/field return number(substring(., 9, 2)))
In XSLT 1.0 it's much harder. See for example http://www.biglist.com/lists/xsl-lis.../msg00968.html
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi Node Condition just2click XSLT 4 February 4th, 2007 04:55 PM
Help: Running Sum (or Cumulative Sum) timdasa VB Databases Basics 1 August 22nd, 2006 03:12 PM
multi-multi-multiple Insert with subquery??? jmjyiannis SQL Server 2000 1 May 5th, 2006 02:20 PM
Condition mateenmohd SQL Server 2000 6 May 6th, 2004 03:49 AM
XSL-help-sum of nodes baed on a condition skumar80 XSLT 2 November 8th, 2003 10:08 AM





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