Skip to Content

Bundle messages with same value for a certain tag

Hi,

I am quite new to cloud platform integration and wonder if there is a general pattern how to bundle multiple messages that do have the same value in a certain field/element. For instance consider an XML message with multiple nodes each having a cild node <Date>. In the end I would like to get one message per date. Is that possible at all?

Cheers,

Daniel

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Sep 21, 2017 at 05:16 PM

    Hello Daniel,

    Below should help you Post XSLT mapping have splitter to split 2 separate records of <Postings>.

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:key name="Date" match="Date" use="."/>
    	<xsl:template match="/Postings">
    		<PostingData>
    			<xsl:apply-templates select="Posting/Date[generate-id() = generate-id(key('Date', .)[1])]"/>			</PostingData>
    	</xsl:template>
    	<xsl:template match="Date">
    		<xsl:variable name="currentDate" select="."/>
    		<Postings>			
    			<xsl:for-each select="key('Date', $currentDate)">			
    				<Posting>
    					<Company>
    						<xsl:value-of select="../Company"/>
    					</Company>
    					<Date>
    						<xsl:value-of select="$currentDate"/>
    					</Date>
    					<Account>
    						<xsl:value-of select="../Account"/>
    					</Account>
    					<CreditAmount>
    						<xsl:value-of select="../CreditAmount"/>
    					</CreditAmount>
    					<DebitAmount>
    						<xsl:value-of select="../DebitAmount"/>
    					</DebitAmount>
    					<Currency>
    						<xsl:value-of select="../Currency"/>
    					</Currency>
    				</Posting>
    			</xsl:for-each>
    		</Postings>
    	</xsl:template>
    </xsl:stylesheet>
    

    Regards,

    Sriprasad Shivaram Bhat

    Add comment
    10|10000 characters needed characters exceeded

    • Hello Daniel,

      There are no recommendation as such wrt Scripting or XSLT. It completely depends on your requirement and comfort zone.

      XSLT is good old technology to parse XML and many of the integration consultants are familiar,where as groovy is but newer.

      From performance perspective I have not seen much difference as such.

      May by fellow folks from our community can shed their observations.

      Regards,

      Sriprasad Shivaram Bhat

  • Sep 20, 2017 at 08:00 AM

    Hello Daniel,

    There is no standard step available to do the same,you might need to write script or XSLT to achieve the same.

    If you can share input and expected output will try to help you.

    Regards,

    Sriprasad Shivaram Bhat

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 21, 2017 at 01:12 PM

    Hi,

    Thanks for your reply. Basically I have an input such as

    <Postings>
    	<Posting>
    		<Company>2000</Company>
    		<Date>2017-04-30</Date>
    		<Account>1123</Account>
    		<DebitAmount>2</DebitAmount>
    		<CreditAmount/>
    		<Currency>EUR</Currency>
    	</Posting>
    	<Posting>
    		<Company>2000</Company>
    		<Date>2017-04-30</Date>
    		<Account>2222</Account>
    		<DebitAmount/>
    		<CreditAmount>2</CreditAmount>
    		<Currency>EUR</Currency>
    	</Posting>
    	<Posting>
    		<Company>2000</Company>
    		<Date>2017-04-31</Date>
    		<Account>1123</Account>
    		<DebitAmount>100</DebitAmount>
    		<CreditAmount/>
    		<Currency>EUR</Currency>
    	</Posting>
    	<Posting>
    		<Company>2000</Company>
    		<Date>2017-04-31</Date>
    		<Account>1123</Account>
    		<DebitAmount>100</DebitAmount>
    		<CreditAmount/>
    		<Currency>EUR</Currency>
    	</Posting>
    </Postings>

    Desired Result would be two messages aggregated based on the date:

    <Postings>
    	<Posting>
    		<Company>2000</Company>
    		<Date>2017-04-30</Date>
    		<Account>1123</Account>
    		<DebitAmount>2</DebitAmount>
    		<CreditAmount/>
    		<Currency>EUR</Currency>
    	</Posting>
    	<Posting>
    		<Company>2000</Company>
    		<Date>2017-04-30</Date>
    		<Account>2222</Account>
    		<DebitAmount/>
    		<CreditAmount>2</CreditAmount>
    		<Currency>EUR</Currency>
    	</Posting>
    </Postings>
    <Postings>
    	<Posting>
    		<Company>2000</Company>
    		<Date>2017-04-31</Date>
    		<Account>1123</Account>
    		<DebitAmount>100</DebitAmount>
    		<CreditAmount/>
    		<Currency>EUR</Currency>
    	</Posting>
    	<Posting>
    		<Company>2000</Company>
    		<Date>2017-04-31</Date>
    		<Account>1123</Account>
    		<DebitAmount>100</DebitAmount>
    		<CreditAmount/>
    		<Currency>EUR</Currency>
    	</Posting>
    </Postings>

    Regards,

    Daniel

    Add comment
    10|10000 characters needed characters exceeded