w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
XSLT 1.0 group by date
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
   <xsl:output method="xml" indent="yes" />

   <xsl:key name="groups" match="/transactions/transaction"
use="element[@name='Date']" />

   <xsl:template match="/transactions">
      <transactions>
         <xsl:apply-templates select="transaction[generate-id(.) =
generate-id(key('groups', element[@name='Date'])[1])]" />
      </transactions>
   </xsl:template>

   <xsl:template match="transaction">
      <date id="{element[@name='Date']}">
         <sum>
            <xsl:value-of select="format-number(sum(key('groups',
element[@name='Date'])/element[@name='Amount']), '#.00')" />
         </sum>
         <numberOfTrans>
            <xsl:value-of select="count(key('groups',
element[@name='Date']))" />
         </numberOfTrans>
         <xsl:for-each select="key('groups', element[@name='Date'])">
            <xsl:copy>
               <xsl:copy-of select="@*" />
               <xsl:copy-of select="element[@name='Amount']" />
            </xsl:copy>
         </xsl:for-each>
      </date>
   </xsl:template>
</xsl:stylesheet>




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.