cancel
Showing results for 
Search instead for 
Did you mean: 

XSL Mapping Query

former_member185845
Active Participant
0 Kudos

Dear Collegues,

i am doing Simple xsl transformation ,

source xml

<?xml version="1.0" encoding="UTF-8"?>

<!Sample XML file generated by XMLSpy v2006 sp2 U (http://www.altova.com)>

<ns0:Request xmlns:ns0="http://sap.com/xi/demo/httpxsd">

<CARRID>LH</CARRID>

<CONNID>0400</CONNID>

</ns0:Request>

XSL file

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- <xsl:output method="xml" indent="yes"/> -->

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">

<ns0:ZSYNCCONNECTIONDET xmlns:ns="urn:sap-com:document:sap:rfc:functions">

<carrid>

<xsl:value-of select="/ns0:Request/CARRID"/>

</carrid>

<connid>

<xsl:value-of select="/ns0:Request/CONNID"/>

</connid>

</ns0:ZSYNCCONNECTIONDET>

</xsl:template>

</xsl:stylesheet>

when i execute the xsl progtram i am getting the output without the values ,

output:

<?xml version="1.0" encoding="UTF-8"?>

<ns0:ZSYNCCONNECTIONDET xmlns:ns0="urn:sap-com:document:sap:rfc:functions">

<carrid></carrid>

<connid></connid>

</ns0:ZSYNCCONNECTIONDET>

any suggestions?

Regards

shekar chandra

Accepted Solutions (1)

Accepted Solutions (1)

henrique_pinto
Active Contributor
0 Kudos

> XSL file

> <?xml version="1.0" encoding="UTF-8"?>

> <xsl:stylesheet version="1.0"

> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

> <!-- <xsl:output method="xml" indent="yes"/> -->

> <xsl:output method="xml" indent="yes"/>

> <xsl:template match="/">

> <ns0:ZSYNCCONNECTIONDET

> IONDET

> <b>xmlns:ns</b>="urn:sap-com:document:sap:rfc:functions">

> <carrid>

> <xsl:value-of

> <xsl:value-of select="/ns0:Request/CARRID"/>

> </carrid>

> <connid>

> <xsl:value-of

> <xsl:value-of select="/ns0:Request/CONNID"/>

> </connid>

> </ns0:ZSYNCCONNECTIONDET>

> </xsl:template>

> </xsl:stylesheet>

You missed a '0' in the part in bold.

It should be " xmlns:ns0: ... ". 🐵

Regards,

Henrique.

Former Member
0 Kudos

Hi Henrique,

It is not the "0" alone what he missed, the namespace itself is wrong. But irrespective of that, as per my above message, if he ensures that the namespace of Input XML is used in the map, then it would work perfectly.

Regards

Vishnu

former_member185845
Active Participant
0 Kudos

Dear Friends,

Thanks for your pointers,

Regarding as per vishnu,

<i><b>the namespace itself is wrong. </b></i>

I really didnt understant why the name space is wrong,

as the target message is RFC ,

<i><b>if he ensures that the namespace of Input XML is used in the map</b></i>

i really didnt get this?

Regards

chandra

Former Member
0 Kudos

Hi Chandra,

As mentioned in my msgs, you have to use the Namespace of the Input XML in your XSL code (as per how your programme) to get the desired output.

pls check the below code, where I have added the same in the xsl:stylesheet tag.

Try it now. This works.

XSL file

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" <b>xmlns:ns0="http://sap.com/xi/demo/httpxsd"</b>>

<!-- <xsl:output method="xml" indent="yes"/> -->

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">

<ns0:ZSYNCCONNECTIONDET xmlns:ns="urn:sap-com:document:sap:rfc:functions">

Regards

Vishnu

henrique_pinto
Active Contributor
0 Kudos

> Hi Henrique,

>

> It is not the "0" alone what he missed, the

> he namespace itself is wrong. But irrespective of

> that, as per my above message, if he ensures that the

> namespace of Input XML is used in the map, then it

> would work perfectly.

>

> Regards

> Vishnu

Vishnu,

You were right in the part that not only the 0 is missing, but the namespace is not wrong, since he needs it to define output message's namespace. The point is that he has forgot to define input namespace and has used the same prefix for input and output.

Chandra,

For correction, you should add that 0 to ns (so it's ns0) and add the namespace&prefix for the input message, and use this other prefix for refering to the input fields.

In order to don't get confused, you should use prefixes that say directly which message you are refering to. Your xslt could be like (modifications in bold):

XSL file

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" <b>xmlns:input="http://sap.com/xi/demo/httpxsd"</b>>

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">

<<b>output</b>:ZSYNCCONNECTIONDET xmlns:<b>output</b>="urn:sap-com:document:sap:rfc:functions">

<carrid>

<xsl:value-of select="/<b>input</b>:Request/CARRID"/>

</carrid>

<connid>

<xsl:value-of select="/<b>input</b>:Request/CONNID"/>

</connid>

</<b>output</b>:ZSYNCCONNECTIONDET>

</xsl:template>

</xsl:stylesheet>

Regards,

Henrique.

former_member185845
Active Participant
0 Kudos

Dear Henrique & prakash,

Thanks for your inputs & the sample code.Its working fine now.

Regards

shekar chandra

Answers (1)

Answers (1)

former_member206604
Active Contributor
0 Kudos

Hi,

Try this

<xsl:value-of select="/ns0:Request/CARRID"/>

instead of

<xsl:value-of select="Request/CARRID"/>

Thanks,

Prakash

former_member185845
Active Participant
0 Kudos

Dear prakash,

I tried using both the ways,i didnt get any result.

Regards

chandra

Former Member
0 Kudos

Hi,

Use the below Namespace, additionally in any one of the tags where you specify the other namespaces.

1) in <xsl:stylesheet or

2) in <ns0:ZSYNCCONNECTIONDET

xmlns:ns0="http://sap.com/xi/demo/httpxsd"

Hope this fixes your issue,

Regards

Vishnu

former_member206604
Active Contributor
0 Kudos

Hi,

Try this and I think should work

Copy the following code and save it as Nspace.xsl

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="no"/>
  <xsl:template match="/|comment()|processing-instruction()">
    <xsl:copy>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="*">
    <xsl:element name="{local-name()}">
      <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
  </xsl:template>
  <xsl:template match="@*">
    <xsl:attribute name="{local-name()}">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
</xsl:stylesheet>

Import in Imported Archive and during your Interface Mapping add one more mapping of type XSLT and add this Nspace.xsl first and then your XSLT file which should hae the code as follows.

<xsl:value-of select="Request/CARRID"/>

wichout namespace and not like this

<xsl:value-of select="/ns0:Request/CARRID"/>

Thanks,

Prakash