on 09-25-2007 12:47 PM
Hello,
how to loop over any node in the source message to lookup
a single field content. With the SAP Business Connector
i couid simply use the LOOP function. In XI, i guess i need a
extended UDF'?! But how does it look like?
In the following example, <b>subnode</b> in the source occurs 1 - n.
<b>Source message:</b>
<i>node</i>
value1 = VAL1
value2 = VAL2
<i>subnode</i>
qualifier = A
value = VALA
<i>/subnode
subnode</i>
qualifier = B
value = VALB
<i>/subnode</i>
<i>subnode</i>
qualifier = C
value = VALC
<i>/subnode</i>
<i>/node</i>
<b>Mapping Rules:</b>
value1 --> value1
value2 --> value2
(loop over all subnodes)
if qualifier equals "C"
then value --> value3
<b>Desired destination message:</b>
<i>node</i>
value1 = VAL1
value2 = VAL2
value3 = VALC
<i>/node</i>
Gunnar,
You need an UDF function to do this. pass the qualifier and value to the UDF. make sure the context of the inputs is at the node level. You will have 2 string arrays. Loop through the qualifer array to check the condition and use the index of the matching text to return the value from the second array.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you need to do a more scaleable solution the graphical tool can get quite cumbersome, so another option would be to use an XSLT mapping.
source.xml
<?xml version="1.0" encoding="UTF-8"?>
<node>
<value1>VAL1</value1>
<value2>VAL2</value2>
<subnode>
<qualifier>A</qualifier>
<value>VALA</value>
</subnode>
<subnode>
<qualifier>B</qualifier>
<value>VALB</value>
</subnode>
<subnode>
<qualifier>C</qualifier>
<value>VALC</value>
</subnode>
</node>
transformation.xslt
<xsl:stylesheet version="1.0" xmlns:tns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<node>
<xsl:apply-templates/>
</node>
</xsl:template>
<xsl:template match="node">
<value1><xsl:value-of select="value1" /></value1>
<value2><xsl:value-of select="value2" /></value2>
<xsl:apply-templates select="subnode" />
</xsl:template>
<xsl:template match="subnode"><xsl:if test="qualifier='C'"><value3><xsl:value-of select="value" /></value3></xsl:if></xsl:template>
</xsl:stylesheet>
result.xml
<?xml version="1.0" encoding="UTF-8"?>
<node xmlns:tns="http://www.w3.org/1999/xhtml">
<value1>VAL1</value1>
<value2>VAL2</value2>
<value3>VALC</value3>
</node>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
looping thru a node can be achieved by the following code..
for(int i=0; i<subnode.length; i++)
{
//write your code.
}
U can have a graphical mapping....
Qualifier & Constant C---> equalsS---> If--
> value 3.
Map value----
> Then(of IF structure).
http://www.w3schools.com/dom/dom_nodes_nodelist.asp
Regards
San
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gunnar,
Welcome to XI. It is going to be a great experience for you in XI if you have come from a BC back ground.
Mapping in XI is quite different from BC. In XI you dont have to do loops. It is automaticaly taken care of (provided you have mapped the root nodes)
Answering your question,
1. Map node of source to node of target (Thisa will ensure the loop)
2. Value1of source to value1 of target
3. Value2 of source to value2 of target
4. Have a if without else and do the condition check to map value3.
Regards,
Jai Shankar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
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.