cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT mapping

maheswarareddykonda
Active Contributor
0 Kudos

Hi Experts,

i am new to XSLT mapping , but i used few xslt codes which were found in few blogs, and those are running fine..but need to keep both codintions in single code..below are codes

Code1: this is doing removing the all namespaces in payload


<?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: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:template match="@*[local-name(.)='noNamespaceSchemaLocation']"/>

</xsl:stylesheet>

Code2: its doing adding my required Message type and namespace with tacking header and body from payload


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

<xsl:stylesheet version="1.0" exclude-result-prefixes="ns0 ns1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="http://Softel.com/xi/Softel_SC_PLANNING/GPEO/TransactionalData" xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge" > 

   <xsl:output method="xml" encoding="UTF-8"/> 

   <xsl:template match="/"> 

      <ns0:Envelope xmlns:ns0="http:Business.com" >

            <xsl:copy> 

               <xsl:apply-templates select="//Header"/> 

            </xsl:copy> 

            <xsl:copy> 

               <xsl:apply-templates select="//Body"/> 

            </xsl:copy>      

      </ns0:Envelope> 

   </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>

please help me if both condition are possible to merge in single code and achieve.

Thanks,

Maheswarareddy

Accepted Solutions (1)

Accepted Solutions (1)

pvishnuvardan_reddy
Active Contributor
0 Kudos

Hi Mahesh,

I assume your query is on handling namespaces.

If yes, then can you look out the possibility of using XML anonymiser bean at the channel level for the same.

SAPTechnical.COM - XML Anonymizer Bean in Communication Channel to remove namespace prefix in XML Pa...

maheswarareddykonda
Active Contributor
0 Kudos

Hi Vishu,

actually i am getting so many namespaces from receiver third party system such as xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> and more in between also. with different prefixes.

so i want to remove all namespaces and put my msgmapping namespace with prefix ns0

like xmlns:ns0="http:Business.com"( need in output)

however i tried as per blog which u shared

and getting error like below

20.08.2015 12:28:50.112InformationMP: processing local module localejbs/AF_Modules/XMLAnonymizerBean
20.08.2015 12:28:50.436ErrorAnonymizer: unmatched value pairs in anonymizer.acceptNamespaces
20.08.2015 12:28:50.437ErrorMP: exception caught with cause java.util.NoSuchElementException
20.08.2015 12:28:50.442ErrorException caught by adapter framework: {0}
20.08.2015 12:28:50.443Error

Transmitting the message using connection AFW failed, due to: com.sap.engine.interfaces.messaging.api.exception.MessagingException: java.util.NoSuchElementException

BR,

Maheswarareddy

pvishnuvardan_reddy
Active Contributor
0 Kudos

HI Mahesh,

If you want to keep the only mentioned namespace, then give the parameter value as below

http:Business.com ns0


Try this and let me know if you still having issues.

maheswarareddykonda
Active Contributor
0 Kudos

Hi Vishnu,

i added as you suggested(http:Business.com ns0) its running fine but output is below

- <Envelope>

- <Header>

- <Security mustUnderstand="1">

- <Timestamp Id="_0">

<Created>2015-08-20T13:11:55.732Z</Created>

<Expires>2015-08-20T13:16:55.732Z</Expires>

</Timestamp>

</Security>

</Header>



   And i am expecting below

- <ns0:Envelope xmlns:ns0="http:Business.com">

- <Header>

- <Security mustUnderstand="1">

- <Timestamp Id="_0">

<Created>2015-08-20T13:11:55.732Z</Created>

<Expires>2015-08-20T13:16:55.732Z</Expires>

</Timestamp>

</Security>

</Header>

former_member203641
Participant
0 Kudos

Hi Mahesha,

Can you post following in this thread ? so that I can understand your requirement

1. Sample xml of your source structure

2. sample soap request of soapUI containing only the parameters which are mandatory for you for calling service.

Thanks,

Amit

pvishnuvardan_reddy
Active Contributor
0 Kudos

Hi Mahesh,

Can you share us the transformed xml file before coming to the channel level.

Using anonymiser bean, whatever the namespaces mentioned in the parameter list will only be present after the bean.

maheswarareddykonda
Active Contributor
0 Kudos

Hi Vishnu,

i am using this bean at receiver channel to convert response msg.

response is coming like below from receiver.

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">

   <s:Header>

      <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">

         <u:Timestamp u:Id="_0">

            <u:Created>2015-08-20T12:18:33.970Z</u:Created>

            <u:Expires>2015-08-20T12:23:33.970Z</u:Expires>

         </u:Timestamp>

      </o:Security>

   </s:Header>

   <s:Body>

..

...

..

</s:Body>

</s:Envelope>

and when i use bean below is the output.here namespace is missing

<Envelope>

<Header>

<Security mustUnderstand="1">

<Timestamp Id="_0">

  <Created>2015-08-20T14:00:46.331Z</Created>

  <Expires>2015-08-20T14:05:46.331Z</Expires>

  </Timestamp>

  </Security>

  </Header>

<Body>

..

...

...

</Body>

</Envelope>

and i am expecting like below.

<ns0:Envelope xmlns:ns0="http:Business.com">

<Header>

      <Security s:mustUnderstand="1">

         <Timestamp Id="_0">

            <Created>2015-08-20T12:18:33.970Z</Created>

            <Expires>2015-08-20T12:23:33.970Z</Expires>

         </Timestamp>

      </Security>

   </Header>

<Body>

..

...

..

</Body>

</ns0:Envelope>

maheswarareddykonda
Active Contributor
0 Kudos

Hi Amit,

i have shared below, please check and let me know why that namespace is missing when i use AF_Modules/XMLAnonymizerBean.

pvishnuvardan_reddy
Active Contributor
0 Kudos

HI Mahesh,

I guess you need to handle this in the mapping level itself, as using xml anonymiser bean only removes the unwanted namespaces and keeps only the mentioned namespaces in the payload. It doesn't alter the namespaces as we wish.

So, let me check the xslt mapping code for this requirement involving both the conditions as you mentioned.

I am just curious to know, I assume you have shared the wsdl to the webservice team and are they sending the response including soap header data?

maheswarareddykonda
Active Contributor
0 Kudos

Hi Vishnu,

Yes, they are sending in envelope with header and body.

RaghuVamseedhar
Active Contributor
0 Kudos

Mahes,

Please use XSLT map to remove namespaces or directly create required target XML in XSLT.

Answers (1)

Answers (1)

maheswarareddykonda
Active Contributor
0 Kudos

codes were missed in post,

Code1:

<?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: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:template match="@*[local-name(.)='noNamespaceSchemaLocation']"/>

</xsl:stylesheet>

Code2:

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

<xsl:stylesheet version="1.0" exclude-result-prefixes="ns0 ns1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="http://Softel.com/xi/Softel_SC_PLANNING/GPEO/TransactionalData" xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge" > 

   <xsl:output method="xml" encoding="UTF-8"/> 

   <xsl:template match="/"> 

      <ns0:Envelope xmlns:ns0="http:Business.com" >

            <xsl:copy> 

               <xsl:apply-templates select="//Header"/> 

            </xsl:copy> 

            <xsl:copy> 

               <xsl:apply-templates select="//Body"/> 

            </xsl:copy>      

      </ns0:Envelope> 

   </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>