cancel
Showing results for 
Search instead for 
Did you mean: 

Bundle messages with same value for a certain tag

d_weinberg
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Sriprasadsbhat
Active Contributor

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

d_weinberg
Participant
0 Kudos

Thanks for the input. In the meantime I also achieved my goal by implementing a groovy script. Is there any recommendation what to prefer, scripting or XSLT?

Sriprasadsbhat
Active Contributor

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

Answers (2)

Answers (2)

d_weinberg
Participant
0 Kudos

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

Sriprasadsbhat
Active Contributor
0 Kudos

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