on 09-22-2005 9:31 AM
Hi,
i have a xml structur like that:
<root>
<header>
<nr>00010</nr>
</header>
<header>
<nr>00102</nr>
</header>
<item>
<nr>00010</nr>
<value>20</value>
<wight>60</wight>
</item>
<item>
<nr>00102</nr>
<value>30</value>
<wight>30</wight>
</item>
<desc>
<nr>00010</nr>
<name>Meet</name>
</desc>
<desc>
<nr>00102</nr>
<name>Apple</name>
</desc>
</root>
and want that it looks like that:
<root>
<item>
<nr>00010</nr>
<name>Meet</name>
<value>20</value>
<wight>60</wight>
</item>
<item>
<nr>00102</nr>
<name>Apple</name>
<value>30</value>
<wight>30</wight>
</item>
</root>
for each header tag in source message it must be a item tag in target message.
can i handle this with a XSLT Mapping ?
any Idea?
for me its looks very difficult to do that in a mapping.
Regards,
Robin
Hi Robin,
check this:
[code]
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<root>
<xsl:for-each select="//header/nr">
<xsl:variable name="NR" select="."/>
<item>
<nr>
<xsl:value-of select="."/>
</nr>
<name>
<xsl:value-of select="../../desc/name[../nr=$NR]"/>
</name>
<value>
<xsl:value-of select="../../item/value[../nr=$NR]"/>
</value>
<wight>
<xsl:value-of select="../../item/wight[../nr=$NR]"/>
</wight>
</item>
</xsl:for-each>
</root>
</xsl:template>
</xsl:styleshee
[/code]
Regards,
Udo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think you have your source xml wrong. Try getting your source xml structure to be something like below, the reason being you cannot do a loop (for-each) otherwise.
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<data>
<header>
<nr>00010</nr>
</header>
<item>
<nr>00010</nr>
<value>20</value>
<wight>60</wight>
</item>
<desc>
<nr>00010</nr>
<name>Meet</name>
</desc>
</data>
<data>
<header>
<nr>00102</nr>
</header>
<item>
<nr>00102</nr>
<value>30</value>
<wight>30</wight>
</item>
<desc>
<nr>00102</nr>
<name>Apple</name>
</desc>
</data>
<data>
<header>
<nr>00102</nr>
</header>
<item>
<nr>00102</nr>
<value>30</value>
<wight>40</wight>
</item>
<desc>
<nr>00102</nr>
<name>Apple</name>
</desc>
</data>
</root>
Now if understood your requirement correctly, you need to club all nr together, and also aggregate (sum) their respective values and wight.
The XSLT to achieve that is as follows,
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="nr" match="root/data" use="header/nr"/>
<xsl:template match="/">
<root>
<!-- iterate on each group -->
<xsl:for-each select="root/data[generate-id(.) = generate-id(key('nr', header/nr)[1]) ]">
<xsl:variable name="group" select="key('nr', header/nr)"/>
<xsl:variable name="nr">
<xsl:value-of select="header/nr"/>
</xsl:variable>
<xsl:variable name="name">
<xsl:value-of select="desc/name"/>
</xsl:variable>
<xsl:variable name="value">
<xsl:value-of select="sum($group/item/value)"/>
</xsl:variable>
<xsl:variable name="wight">
<xsl:value-of select="sum($group/item/wight)"/>
</xsl:variable>
<!-- Generate the final XML file -->
<item>
<nr>
<xsl:value-of select="$nr"/>
</nr>
<name>
<xsl:value-of select="$name"/>
</name>
<value>
<xsl:value-of select="$value"/>
</value>
<wight>
<xsl:value-of select="$wight"/>
</wight>
</item>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>
Please have a look at my code sample that i have submitted, which speaks of how to handle such a scenario.
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/xi/xi-code-samples... xslt mapping in sap xi, part i.pdf
cheers
Sameer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sameer,
my sample soure structure is like it is in many idocs.
But i dont want to post the idoc xml structure here
In my case it is the ARTMAS Idoc.
thats also why i can't change my source structure.
But you can loop to the structure when you do it like Udo says.
Or you can loop only at the header elements and call a template with parameter(the Number)in this loop to get the other values.
@ $
I try the Message Mapping when i have time for that
Thanks and Regards,
Robin
hi Robin,
isn't this what you're looking for:
http://help.sap.com/saphelp_nw04/helpdata/en/ec/8fb142d043b911e10000000a1550b0/content.htm
also have a look at this:
http://help.sap.com/saphelp_nw04/helpdata/en/38/85b142fa26c811e10000000a1550b0/content.htm
Regards,
michal
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.