[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: "sum" of "substring"

Subject: RE: "sum" of "substring"
From: Colin Simpson <Colin.Simpson@xxxxxxxxxxxxxxx>
Date: Thu, 23 Oct 2003 13:09:51 +0100
colin simpson
Thanks very much for the suggestions.

I'm an XSL newbie, so I'll have to figure out exactly what is involved in
each approach.  I particularly like the idea of creating a result tree
fragment, as I've not tried that yet.

Colin Simpson

-----Original Message-----
From: Michael Kay [mailto:mhk@xxxxxxxxx]
Sent: 23 October 2003 13:03
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  "sum" of "substring"


Summing over a computed expression isn't easy in XSLT 1.0. Here are some
possible approaches:

(a) Rather than use the sum() function, do a traversal of the values
using a recursive template, adding the values up as you go.

(b) Create a result tree fragment containing the computed values, and
use the xx:node-set() function to access the nodes in the RTF and sum()
over them

(c) Use XPath 2.0: sum(for $i in $seq return f($i))

(d) Use the saxon:sum() extension function in Saxon 6.5.3

(e) Use the appropriate template from Dimitre's FXSL library

Michael Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Colin Simpson
> Sent: 23 October 2003 12:24
> To: 'XSL-List@xxxxxxxxxxxxxxxxxxxxxx'
> Subject:  "sum" of "substring"
> 
> 
> Hello
> 
> My problem:
> I have a flat text file that has to be transformed into a 
> predetermined XML file.
> 
> Example: TYPE1Field1AnotherField12.00YetAnotherField445.26FinalField
> TYPE1ABCDEFABCDEFGHIJKL45.00ABCDEFGHIJKLMNO123.45ABCDEFGHIJ
> TYPE2FieldAnother987.65Final
> 
> where the first 5 characters indicate which one of two record 
> layouts it is.
> 
> I first do some rudimentary wrapping of the records, creating 
> an intermediary XML file that I can then use XSLT to process:
> 
> <records> 
> <record>TYPE1Field1AnotherField12.0YetAnotherField445.26FinalF
> ield</record>
> <record>TYPE1ABCDEFABCDEFGHIJKL45.0ABCDEFGHIJKLMNO123.45ABCDEF
> GHIJ</record>
> <record>TYPE2FieldAnother987.65Final</record>
> </records>
> 
> 
> I can populate nodes in the final output XML file by 
> extracting data via "substring", such as 
> <xsl:value-of select="substring(.,28,15)">
> 
> I need to total up certain numeric values within the record 
> of a specific layouts. For example, I want to total up the 
> values that occupy positions 24 thru 28 from all records of 
> "TYPE1". Is there any way of doing this? I thought I should 
> use "sum" but I can't figure out the syntax needed.
> 
> Kind regards
> Colin Simpson
> 
> **************************************************************
> **************
> 
> This email and any files transmitted with it are confidential 
> and intended 
> solely for the use of the individual or entity to whom they 
> are addressed. 
> If you have received this email in error please notify the 
> system manager. 
> 
> **************************************************************
> **************
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
****************************************************************************

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. 
If you have received this email in error please notify the system manager. 

****************************************************************************

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.