XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Bijayananda PandaSubject: Grouping Problem
Author: Bijayananda Panda
Date: 12 Sep 2005 07:31 AM
Hi All,
Can some body help me over the below problem. I am very new to XSLT Mapping.

The Input File is:

<LegacyPayrollRequests>
<LegacyPayrollRequest>
<LegpayNr>111</LegpayNr>
<Betrg>4444.00</Betrg>
</LegacyPayrollRequest>
<LegacyPayrollRequest>
<LegpayNr>222</LegpayNr>
<Betrg>6666.00</Betrg>
</LegacyPayrollRequest>
<LegacyPayrollRequest>
<LegpayNr>111</LegpayNr>
<Betrg>5555.00</Betrg>
</LegacyPayrollRequest>
<LegacyPayrollRequest>
<LegpayNr>222</LegpayNr>
<Betrg>7777.00</Betrg>
</LegacyPayrollRequest>
<LegacyPayrollRequest>
<LegpayNr>333</LegpayNr>
<Betrg>8888.00</Betrg>
</LegacyPayrollRequest>
</LegacyPayrollRequests>

Target Output is:
<REM_SPEC01>
<IDOC BEGIN="1">
<E1BP7012_1>
<EMPLOYEENUMBER>111</EMPLOYEENUMBER>
<AMOUNT>4444.00</AMOUNT>
</E1BP7012_1>
<E1BP7012_1>
<EMPLOYEENUMBER>111</EMPLOYEENUMBER>
<AMOUNT>5555.00</AMOUNT>
</E1BP7012_1>
</IDOC>
<IDOC BEGIN="2">
<E1BP7012_1>
<EMPLOYEENUMBER>222</EMPLOYEENUMBER>
<AMOUNT>6666.00</AMOUNT>
</E1BP7012_1>
<E1BP7012_1>
<EMPLOYEENUMBER>222</EMPLOYEENUMBER>
<AMOUNT>7777.00</AMOUNT>
</E1BP7012_1>
</IDOC>
<IDOC BEGIN="3">
<E1BP7012_1>
<EMPLOYEENUMBER>333</EMPLOYEENUMBER>
<AMOUNT>8888.00</AMOUNT>
</E1BP7012_1>
</IDOC>
</REM_SPEC01>

The XSL is:
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<REM_SPEC01>
<xsl:for-each select="LegacyPayrollRequests/LegacyPayrollRequest">
<IDOC BEGIN="1">
<xsl:attribute name="BEGIN">
<xsl:value-of select="position()"/>
</xsl:attribute>
<E1BP7012_1>
<EMPLOYEENUMBER>
<xsl:value-of select="LegpayNr"/>
</EMPLOYEENUMBER>
<AMOUNT>
<xsl:value-of select="Betrg"/>
</AMOUNT>
</E1BP7012_1>
</IDOC>
</xsl:for-each>
</REM_SPEC01>
</xsl:template>
</xsl:stylesheet>

This XSL generates 5 Idocs as it is. I know there should be some check/grouping logic to be written before <IDOC> and <E1BP7012_1> level.
Can any one help me please.

Thanks.
Bijayananda

Postnext
Alberto MassariSubject: Grouping Problem
Author: Alberto Massari
Date: 12 Sep 2005 08:19 AM
Hi Bijayananda,
can you be more specific about the missing grouping/logic you are referring to? Given the input XML and the requested output, I don't see what's missing in your XSLT stylesheet.

Thanks,
Alberto

Postnext
Bijayananda PandaSubject: Grouping Problem
Author: Bijayananda Panda
Date: 12 Sep 2005 08:49 AM
Hi Alberto,
Thanks for the reply. The current XSL generates 5 Idocs, where as my requirement is to generate only 3 IDocs ( 1st Idoc should club together LegpayNrs of 111, 2nd Idoc should club together LegpayNrs of 222 and 3rd Idoc should contain only legpayNr 333 data).

Present XSL is not doing this grouping, instead, its generating 5 separate Idocs.

Hope, this will help you.

Thanks.
Bijayananda

Postnext
Alberto MassariSubject: Grouping Problem
Author: Alberto Massari
Date: 13 Sep 2005 06:35 AM
Hi Bijayananda,
to do grouping you need to use a key:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="employee" match="LegacyPayrollRequests/LegacyPayrollRequest" use="LegpayNr"/>

<xsl:template match="/">
<REM_SPEC01>
<xsl:for-each select="LegacyPayrollRequests/LegacyPayrollRequest[ generate-id() = generate-id(key('employee', LegpayNr)[1]) ]">
<xsl:variable name="curpayNr" select="LegpayNr"/>
<IDOC BEGIN="{position()}">
<E1BP7012_1>
<EMPLOYEENUMBER>
<xsl:value-of select="LegpayNr"/>
</EMPLOYEENUMBER>
<AMOUNT>
<xsl:value-of select="sum(/LegacyPayrollRequests/LegacyPayrollRequest[LegpayNr=$curpayNr]/Betrg)"/>
</AMOUNT>
</E1BP7012_1>
</IDOC>
</xsl:for-each>
</REM_SPEC01>
</xsl:template>
</xsl:stylesheet>

Hope this helps,
Alberto

Postnext
Bijayananda PandaSubject: Grouping Problem
Author: Bijayananda Panda
Date: 13 Sep 2005 08:08 AM
Dear Alberto,
Thanks for the reply. In the output, i want 3 Idocs, but every Idoc should club together the LegpayNr data including Tags. For example, the 1st Idoc should contain:

<IDOC BEGIN="1">
<E1BP7012_1>
<EMPLOYEENUMBER>111</EMPLOYEENUMBER>
<AMOUNT>4444.00</AMOUNT>
</E1BP7012_1>
<E1BP7012_1>
<EMPLOYEENUMBER>111</EMPLOYEENUMBER>
<AMOUNT>5555.00</AMOUNT>
</E1BP7012_1>
</IDOC>


The Required Outpt:
==================
<REM_SPEC01>
<IDOC BEGIN="1">
<E1BP7012_1>
<EMPLOYEENUMBER>111</EMPLOYEENUMBER>
<AMOUNT>4444.00</AMOUNT>
</E1BP7012_1>
<E1BP7012_1>
<EMPLOYEENUMBER>111</EMPLOYEENUMBER>
<AMOUNT>5555.00</AMOUNT>
</E1BP7012_1>
</IDOC>
<IDOC BEGIN="2">
<E1BP7012_1>
<EMPLOYEENUMBER>222</EMPLOYEENUMBER>
<AMOUNT>6666.00</AMOUNT>
</E1BP7012_1>
<E1BP7012_1>
<EMPLOYEENUMBER>222</EMPLOYEENUMBER>
<AMOUNT>7777.00</AMOUNT>
</E1BP7012_1>
</IDOC>
<IDOC BEGIN="3">
<E1BP7012_1>
<EMPLOYEENUMBER>333</EMPLOYEENUMBER>
<AMOUNT>8888.00</AMOUNT>
</E1BP7012_1>
</IDOC>
</REM_SPEC01>

Thanks.
Bijayananda

Postnext
Alberto MassariSubject: Grouping Problem
Author: Alberto Massari
Date: 14 Sep 2005 03:53 AM
Hi Bijayananda,
if you don't want to sum the paychecks, but just cluster together, you need to iterate over all the elements matching the current employee number, like this:

<xsl:for-each select="/LegacyPayrollRequests/LegacyPayrollRequest[LegpayNr=$curpayNr]">
<E1BP7012_1>
<EMPLOYEENUMBER>
<xsl:value-of select="LegpayNr"/>
</EMPLOYEENUMBER>
<AMOUNT>
<xsl:value-of select="Betrg"/>
</AMOUNT>
</E1BP7012_1>
</xsl:for-each>

Hope this helps,
Alberto

Posttop
Bijayananda PandaSubject: Grouping Problem
Author: Bijayananda Panda
Date: 14 Sep 2005 04:35 AM
Dear Alberto,
Thanks for your help. It worked fine.

Regards.
Bijayananda.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.