|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: "sum" of "substring"
Hi Colin,
Sorry for coming in late to answer..
If I understood the problem correctly, *the following
XSL hopefully solves the problem* ..
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan">
<xsl:output method="text" version="1.0"
encoding="UTF-8" indent="yes"/>
<xsl:template match="/records">
<xsl:variable name="xml-subset">
<xsl:for-each select="record">
<xsl:if test="substring(. , 1, 5) = 'TYPE1'">
<a>
<xsl:value-of select="substring(. , 24, 5)"/>
</a>
</xsl:if>
</xsl:for-each>
</xsl:variable>
Desired total -- <xsl:value-of
select="sum(xalan:nodeset($xml-subset)//a)" />
</xsl:template>
</xsl:stylesheet>
I am assuming, the following XML is already written --
<?xml version="1.0" encoding="UTF-8"?>
<records>
<record>TYPE1Field1AnotherField12.5
YetAnotherField445.26FinalField</record>
<record>TYPE1ABCDEFABCDEFGHIJKL13.0
ABCDEFGHIJKLMNO123.45ABCDEFGHIJ</record>
<record>TYPE2FieldAnother987.65Final</record>
</records>
When the XSL posted by me, is applied to the XML, the
desird sum is produced. I am using, *the nodeset
extension function*, and have introduced a Result Tree
Fragment(RTF), with a XML element <a> , for the sake
of computation..
Hope my answer is useful..
Regards,
Mukul
--- Colin Simpson <Colin.Simpson@xxxxxxxxxxxxxxx>
wrote:
> 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.26FinalField</record>
>
<record>TYPE1ABCDEFABCDEFGHIJKL45.0ABCDEFGHIJKLMNO123.45ABCDEFGHIJ</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
>
__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








