
Complex Integration
Simplified Integration
<!-- Group employees by Cost Center -->
<xsl:for-each-group select="{Entity Name} /{Entity Name}" group-by="{Enter Field to Filter}">
<CostCenter ><xsl:value-of select="current-grouping-key()" /></CostCenter>
<!-- Calculate the Total Cost within the Cost Center -->
<Total_Cost><xsl:value-of select="sum(current-group()/{Enter Field to Sum})"/></Total_Cost>
Input XML :
<CostDetails>
<CostDetails>
<externalCode>1982</externalCode>
<cust_costcenter>3748</cust_costcenter>
<course_cost>960</course_cost>
</CostDetails>
<CostDetails>
<externalCode>1984</externalCode>
<cust_costcenter>3748</cust_costcenter>
<course_cost>850</course_cost>
</CostDetails>
<CostDetails>
<externalCode>1986</externalCode>
<cust_costcenter>3746</cust_costcenter>
<course_cost>740</course_cost>
</CostDetails>
<CostDetails>
<externalCode>1988</externalCode>
<cust_costcenter>3746</cust_costcenter>
<course_cost>630</course_cost>
</CostDetails>
</CostDetails>
Code :
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<output>
<xsl:for-each-group select="CostDetails/CostDetails " group-by="cust_costcenter">
<Center><xsl:value-of select="current-grouping-key()"/></Center>
<Total_Cost><xsl:value-of select="sum(current-group()/course_cost)"/></Total_Cost>
<employees>
<xsl:for-each select="current-group()">
<employee>
<userId><xsl:value-of select="externalCode "/></userId>
<cost><xsl:value-of select="course_cost"/></cost>
<costcenter><xsl:value-of select="cust_costcenter"/></costcenter>
</employee>
</xsl:for-each>
</employees>
</xsl:for-each-group>
</output>
</xsl:template>
</xsl:stylesheet>
Output XML :
<?xml version="1.0" encoding="UTF-8"?>
<output>
<Center>3748</Center>
<Total_Cost>1810</Total_Cost>
<employees>
<employee>
<userId>1982</userId>
<cost>960</cost>
<costcenter>3748</costcenter>
</employee>
<employee>
<userId>1984</userId>
<cost>850</cost>
<costcenter>3748</costcenter>
</employee>
</employees>
<Center>3746</Center>
<Total_Cost>1370</Total_Cost>
<employees>
<employee>
<userId>1986</userId>
<cost>740</cost>
<costcenter>3746</costcenter>
</employee>
<employee>
<userId>1988</userId>
<cost>630</cost>
<costcenter>3746</costcenter>
</employee>
</employees>
</output>
<!-- Within each Cost Center, group by Status -->
<xsl:for-each-group select="current-group()" group-by="{Enter Field to Filter}">
<Status><xsl:value-of select="current-grouping-key()" /></Status>
Input XML :
<CostDetails>
<CostDetails>
<externalCode>1982</externalCode>
<course_status>Active</course_status>
<cust_costcenter>3748</cust_costcenter>
<course_cost>960</course_cost>
</CostDetails>
<CostDetails>
<externalCode>1984</externalCode>
<course_status>Active</course_status>
<cust_costcenter>3748</cust_costcenter>
<course_cost>550</course_cost>
</CostDetails>
<CostDetails>
<externalCode>1981</externalCode>
<course_status>Completed</course_status>
<cust_costcenter>3748</cust_costcenter>
<course_cost>950</course_cost>
</CostDetails>
<CostDetails>
<externalCode>1983</externalCode>
<course_status>Completed</course_status>
<cust_costcenter>3748</cust_costcenter>
<course_cost>250</course_cost>
</CostDetails>
<CostDetails>
<externalCode>1986</externalCode>
<course_status>Completed</course_status>
<cust_costcenter>3746</cust_costcenter>
<course_cost>740</course_cost>
</CostDetails>
<CostDetails>
<externalCode>1988</externalCode>
<course_status>Completed</course_status>
<cust_costcenter>3746</cust_costcenter>
<course_cost>630</course_cost>
</CostDetails>
<CostDetails>
<externalCode>1987</externalCode>
<course_status>Active</course_status>
<cust_costcenter>3746</cust_costcenter>
<course_cost>330</course_cost>
</CostDetails>
<CostDetails>
<externalCode>1989</externalCode>
<course_status>Active</course_status>
<cust_costcenter>3746</cust_costcenter>
<course_cost>430</course_cost>
</CostDetails>
</CostDetails>
Code :
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<output>
<xsl:for-each-group select="CostDetails/CostDetails " group-by="cust_costcenter">
<Center><xsl:value-of select="current-grouping-key()"/></Center>
<xsl:for-each-group select="current-group()" group-by="course_status">
<Status><xsl:value-of select="current-grouping-key()"/></Status>
<Total_Cost><xsl:value-of select="sum(current-group()/course_cost)"/></Total_Cost>
<employees>
<xsl:for-each select="current-group()">
<employee>
<userId><xsl:value-of select="externalCode "/></userId>
<cost><xsl:value-of select="course_cost"/></cost>
<costcenter><xsl:value-of select="cust_costcenter"/></costcenter>
<status><xsl:value-of select="course_status"/></status>
</employee>
</xsl:for-each>
</employees>
</xsl:for-each-group>
</xsl:for-each-group>
</output>
</xsl:template>
</xsl:stylesheet>
Output XML :
<?xml version="1.0" encoding="UTF-8"?>
<output>
<Center>3748</Center>
<Status>Active</Status>
<Total_Cost>1510</Total_Cost>
<employees>
<employee>
<userId>1982</userId>
<cost>960</cost>
<costcenter>3748</costcenter>
<status>Active</status>
</employee>
<employee>
<userId>1984</userId>
<cost>550</cost>
<costcenter>3748</costcenter>
<status>Active</status>
</employee>
</employees>
<Status>Completed</Status>
<Total_Cost>1200</Total_Cost>
<employees>
<employee>
<userId>1981</userId>
<cost>950</cost>
<costcenter>3748</costcenter>
<status>Completed</status>
</employee>
<employee>
<userId>1983</userId>
<cost>250</cost>
<costcenter>3748</costcenter>
<status>Completed</status>
</employee>
</employees>
<Center>3746</Center>
<Status>Completed</Status>
<Total_Cost>1370</Total_Cost>
<employees>
<employee>
<userId>1986</userId>
<cost>740</cost>
<costcenter>3746</costcenter>
<status>Completed</status>
</employee>
<employee>
<userId>1988</userId>
<cost>630</cost>
<costcenter>3746</costcenter>
<status>Completed</status>
</employee>
</employees>
<Status>Active</Status>
<Total_Cost>760</Total_Cost>
<employees>
<employee>
<userId>1987</userId>
<cost>330</cost>
<costcenter>3746</costcenter>
<status>Active</status>
</employee>
<employee>
<userId>1989</userId>
<cost>430</cost>
<costcenter>3746</costcenter>
<status>Active</status>
</employee>
</employees>
</output>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
7 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 |