Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sum function in XSL

Tags:

xslt

The Below is my input XML:

<?xml version="1.0" encoding="utf-8" ?>
<LogiusInhouse>
    <qty9 field="QTY_9,11#">
        <type>90</type>
        <value>12</value>
    </qty9>
    <qty9 field="QTY_9,11#">
        <type>90</type>
        <value>12</value>
    </qty9>
    <dtm9 field="DTM_9,11#">
        <type>145</type>
        <date>20130308</date>
        <format>102</format>
    </dtm9>
</LogiusInhouse>

XSL:

<xsl:template match="/LogiusInhouse">

        <xsl:value-of select="abs(sum(qty9[type='90']/value))div 1000 "/>

</xsl:template>

my problem is i need to get the absolute sum afterthat it has to be divided by 1000 but iam not getting the result.Please help me on this.

like image 793
user3305421 Avatar asked Aug 01 '26 15:08

user3305421


2 Answers

Or, you can use just this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" indent="yes"/>

<xsl:template match="/LogiusInhouse">
    <xsl:value-of select="sum(qty9/value)" />
</xsl:template>

</xsl:stylesheet>
like image 120
Lingamurthy CS Avatar answered Aug 08 '26 19:08

Lingamurthy CS


do not use for-each. use the template below

<xsl:template match="/LogiusInhouse">               
    <xsl:value-of select="sum(//value)"/>                                     
</xsl:template>

using for-each will output 1212 because for-each node (in your code), the result is 12

like image 23
Joel M. Lamsen Avatar answered Aug 08 '26 20:08

Joel M. Lamsen