Sunday, 17 July 2016

Sum of the resultant nodes of the apply template in XSLT


No Explanation, just a example with sample xml's and screen shots.

Request XML:



<?xml version="1.0" encoding="UTF-8" ?>
<process xmlns:ns0="http://xmlns.oracle.com/Application3/SampleProject/BPELProcess1">
   <mulWeight>
      <weight>800</weight>
      <UoMCodeWei>grm</UoMCodeWei>
   </mulWeight>
   <mulWeight>
      <weight>9000</weight>
      <UoMCodeWei>grm</UoMCodeWei>
   </mulWeight>
   <mulWeight>
      <weight>1000000</weight>
      <UoMCodeWei>mrm</UoMCodeWei>
   </mulWeight>
</process>






XSLT File:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns="http://xmlns.oracle.com/Application3/SampleProject/BPELProcess1"
                exclude-result-prefixes="msxsl">
  <xsl:template match="/process">
    <xsl:variable name="resultGroup">
      <xsl:apply-templates select="mulWeight"/>
    </xsl:variable>
    <processResponse>
      <result>
        <xsl:value-of select="sum(msxsl:node-set($resultGroup)/*)"/>
      </result>
    </processResponse>
  </xsl:template>
  <xsl:template match="mulWeight">
    <xsl:if test="UoMCodeWei='grm'">
      <result>
        <xsl:value-of select="weight div 1000"/>
      </result>
    </xsl:if>
    <xsl:if test="UoMCodeWei='mrm'">
      <result>
        <xsl:value-of select="weight div 1000000"/>
      </result>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>


Result XML :

<?xml version = '1.0' encoding = 'UTF-8'?>
<processResponse xmlns="http://xmlns.oracle.com/Application3/SampleProject/BPELProcess1">
   <result>10.8</result>
</processResponse>





No comments:

Post a Comment