on 02-06-2014 8:12 AM
I am stuck with XSLT mapping for split message(Dont want to use graphical),. I want to generate new message type based upon the unique reference id.
Sharing my input and output smaples, please provide me clues on how to make the split-by-value with value change in XSLT for the field where target node will be the message type where as the source field is ReferenceID.(for one unique reference id - one message type to be created).
Source payload
---------------------------------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<MT_Src>
<row>
<ReferenceID>00002001</ReferenceID>
<ReferenceDate>20131220</ReferenceDate>
</row>
<row>
<ReferenceID>00002001</ReferenceID>
<ReferenceDate>20131220</ReferenceDate>
</row>
<row>
<ReferenceID>00002001</ReferenceID>
<ReferenceDate>20131220</ReferenceDate>
</row>
<row>
<ReferenceID>00002001</ReferenceID>
<ReferenceDate>20131220</ReferenceDate>
</row>
<row>
<ReferenceID>00002001</ReferenceID>
<ReferenceDate>20131220</ReferenceDate>
</row>
<row>
<ReferenceID>00002001</ReferenceID>
<ReferenceDate>20131220</ReferenceDate>
</row>
</MT_Src>
------------------------------------------------------------------------------------------------------------------------------
Desired output
<?xml version="1.0" encoding="UTF-8"?>
<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
<ns0:Message1>
<ns1:MT_Tgt xmlns:ns1="TargetNamespace">
<HeaderRecord>
<field1>constant</field1>
<StartingDate>fielld in source is reference date</StartingDate>
<ReferenceID>00002001</ReferenceID>
</HeaderRecord>
<DetailRecord>
<field2>constant</field2>
<ReferenceID>00002001</ReferenceID>
<DocumentDate>fielld in source is reference date</DocumentDate>
</DetailRecord>
<DetailRecord>
<ReferenceID>00002001</ReferenceID>
<DocumentDate>fielld in source is reference date</DocumentDate>
</DetailRecord>
<TrailerRecord>
<field2>constant</field2>
<EndingDate>2fielld in source is reference date</EndingDate>
<ReferenceID>00002001</ReferenceID>
</TrailerRecord>
</ns1:MT_Tgt>
<ns1:MT_Tgt xmlns:ns1="TargetNamespace">
<HeaderRecord>
<field1>constant</field1>
<StartingDate>fielld in source is reference date</StartingDate>
<ReferenceID>00002002</ReferenceID>
</HeaderRecord>
<DetailRecord>
<ReferenceID>00002002</ReferenceID>
<DocumentDate>fielld in source is reference date</DocumentDate>
</DetailRecord>
<TrailerRecord>
<field2>constant</field2>
<EndingDate>fielld in source is reference date</EndingDate>
<ReferenceID>00002002</ReferenceID>
</TrailerRecord>
</ns1:MT_Tgt>
</ns0:Message1>
</ns0:Messages>
-------------------------------------------------------------------------------------------------------------------------
Hello,
Check this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:split="http://sap.com/xi/XI/SplitAndMerge" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<split:Messages>
<Message1>
<xsl:for-each select="//row">
<xsl:sort select="ReferenceID"/>
<xsl:if test="not(ReferenceID = preceding-sibling::row/ReferenceID)">
<MT_Tgt>
<HeaderRecord>
<ReferenceID>
<xsl:value-of select="ReferenceID"/>
</ReferenceID>
<field1>constant</field1>
<StartingDate>
<xsl:value-of select="ReferenceDate"/>
</StartingDate>
</HeaderRecord>
<xsl:call-template name="process_items">
<xsl:with-param name="items" select="ReferenceID"/>
</xsl:call-template>
</MT_Tgt>
</xsl:if>
</xsl:for-each>
</Message1>
</split:Messages>
</xsl:template>
<xsl:template name="process_items">
<xsl:param name="items"/>
<xsl:for-each select="//row">
<xsl:if test="($items = ReferenceID)">
<DetailRecord>
<field2>constant</field2>
<ReferenceID>
<xsl:value-of select="ReferenceID"/>
</ReferenceID>
<DocumentDate>
<xsl:value-of select="ReferenceDate"/>
</DocumentDate>
</DetailRecord>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Thanks
Amit Srivastava
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Prasad,
You can achieve this with multimapping by using the features of graphical mapping which is available with PI itself.
Is there any specific requirement from client to use xslt mapping?
Regards
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Prasad,
what I understand is you are trying to do a field based split (Multi mapping in XSLT)
try this
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:split="http://sap.com/xi/XI/SplitAndMerge" exclude-result-prefixes="<if any xtra NS's>">
<xsl:template match="/">
<split:Messages>
<Message1>
<a:MT_Tgt>
<xsl:for-each select="//MT_Src/ReferenceID">
<HeaderRecord>
<!-- <ur mapping>-->
</HeaderRecord>
</xsl:for-each>
</a:MT_Tgt>
</Message1>
</split:Messages>
</xsl:template>
</xsl:stylesheet>
let me know if any issues.
Thanks,
Aman Gupta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
11 | |
11 | |
10 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.