cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT : Trouble Adding Namespace

Former Member
0 Kudos

I need to add namespace xmlns:prx="urn:sap.com:proxy:SB1:/1SAI/TAS04BED82951A661E02EC4:701:2008/06/06" to my xml document after doing a PI message mapping.

When I run the following XSLT code in my XML editing software, it works as desired. When I import the XSL program and use it at runtime, it is not adding the namespace. Can anyone help?

XSLT:

<?xml version='1.0' encoding='utf-8'?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:prx="urn:sap.com:proxy:SB1:/1SAI/TAS04BED82951A661E02EC4:701:2008/06/06">

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

<xsl:template match="@* | node()">

<xsl:copy>

<xsl:apply-templates select="@* | node()"/>

</xsl:copy>

</xsl:template>

<xsl:template match="/*">

<xsl:copy>

<xsl:copy-of select="document('')/xsl:stylesheet/namespace::*[not(local-name() = 'xsl')]"/>

<xsl:apply-templates select="@* | node()"/>

</xsl:copy>

</xsl:template>

</xsl:stylesheet>

Source:

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

<ns0:ChartOfAccountsReplicationConfimation xmlns:ns0="http://sap.com/xi/SAPGlobal20/Global">

<MessageHeader>

<UUID>4C321305CA1400AAE10080000A98800D</UUID>

<ReferenceUUID>4bff533d-2452-00f2-e100-80000a98800c</ReferenceUUID>

<CreationDateTime>2010-07-06T13:57:30Z</CreationDateTime>

<SenderBusinessSystemID>ERP_GTPSRM_ECC6_S1</SenderBusinessSystemID>

<RecipientBusinessSystemID>EDG_030_BusinessSystem</RecipientBusinessSystemID>

</MessageHeader>

<Log>

<BusinessDocumentProcessingResultCode>3</BusinessDocumentProcessingResultCode>

<MaximumLogItemSeverityCode>1</MaximumLogItemSeverityCode>

<Item>

<Note>Processed by PI</Note>

</Item>

</Log>

</ns0:ChartOfAccountsReplicationConfimation>

Desired Target:

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

<ns0:ChartOfAccountsReplicationConfimation xmlns:ns0="http://sap.com/xi/SAPGlobal20/Global" xmlns:prx="urn:sap.com:proxy:SB1:/1SAI/TAS04BED82951A661E02EC4:701:2008/06/06">

<MessageHeader>

<UUID>4C321305CA1400AAE10080000A98800D</UUID>

<ReferenceUUID>4bff533d-2452-00f2-e100-80000a98800c</ReferenceUUID>

<CreationDateTime>2010-07-06T13:57:30Z</CreationDateTime>

<SenderBusinessSystemID>ERP_GTPSRM_ECC6_S1</SenderBusinessSystemID>

<RecipientBusinessSystemID>EDG_030_BusinessSystem</RecipientBusinessSystemID>

</MessageHeader>

<Log>

<BusinessDocumentProcessingResultCode>3</BusinessDocumentProcessingResultCode>

<MaximumLogItemSeverityCode>1</MaximumLogItemSeverityCode>

<Item>

<Note>Processed by PI</Note>

</Item>

</Log>

</ns0:ChartOfAccountsReplicationConfimation>

Accepted Solutions (1)

Accepted Solutions (1)

stefan_grube
Active Contributor
0 Kudos

May I ask why you need this namespace?

The prefiy prx is not used in the document, so the namespace would not have any purpose in the target document.

Former Member
0 Kudos

These are confirmations back to an SAP MDGF system. Confirmations coming from another source are working back in MDGF, and the only visible message difference is that they contain this namespace.

stefan_grube
Active Contributor
0 Kudos

Your XSLT could be something like this:

<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/*">
<ns0:ChartOfAccountsReplicationConfimation xmlns:ns0="http://sap.com/xi/SAPGlobal20/Global" xmlns:prx="urn:sap.com:proxy:SB1:/1SAI/TAS04BED82951A661E02EC4:701:2008/06/06">
<xsl:copy>
   have some logic for copy Message header and log
</xsl:copy>
</ns0:ChartOfAccountsReplicationConfimation>
</xsl:template>
</xsl:stylesheet>

Former Member
0 Kudos

I had something like this at first, but it doubles up the ChartOfAccountsReplicationConfimation node. I will just keep messing with it.

I obviously need to get better at XSLT.

stefan_grube
Active Contributor
0 Kudos

Leave this part away:

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

and start directly with

<xsl:template match="/">

Former Member
0 Kudos

Thanks for staying with me, but that leaves me missing nodes throughout the output.

<?xml version="1.0" encoding="UTF-8"?><ns0:ChartOfAccountsReplicationConfimation xmlns:ns0="http://sap.com/xi/SAPGlobal20/Global" xmlns:prx="urn:sap.com:proxy:SB1:/1SAI/TAS04BED82951A661E02EC4:701:2008/06/06">

4C320682CA1400AAE10080000A98800D

4bff533d-2452-00f2-e100-80000a98800c

2010-07-06T11:55:15Z

ERP_GTPSRM_ECC6_S1

EDG_030_BusinessSystem

3

1

Processed by PI

</ns0:ChartOfAccountsReplicationConfimation>

stefan_grube
Active Contributor
0 Kudos

Instead of <xsl:copy> you use the statement:

<xsl:copy-of select="..." />

Try following:

<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
<xsl:template match="/*">
<ns0:ChartOfAccountsReplicationConfimation xmlns:ns0="http://sap.com/xi/SAPGlobal20/Global" xmlns:prx="urn:sap.com:proxy:SB1:/1SAI/TAS04BED82951A661E02EC4:701:2008/06/06">
<xsl:copy-of select="//MessageHeader" />
<xsl:copy-of select="//Log" />
</ns0:ChartOfAccountsReplicationConfimation>
</xsl:template>
</xsl:stylesheet>

Check this page for a reference:

http://w3schools.com/xsl/default.asp

Former Member
0 Kudos

Thank You Stefan.

This code works for me in PI. What is odd is that in my EditiX xml editor program this same code is giving me output missing node names.

<?xml version="1.0" encoding="UTF-8"?><ns0:ChartOfAccountsReplicationConfimation xmlns:ns0="http://sap.com/xi/SAPGlobal20/Global" xmlns:prx="urn:sap.com:proxy:SB1:/1SAI/TAS04BED82951A661E02EC4:701:2008/06/06">

4C320682CA1400AAE10080000A98800D

4bff533d-2452-00f2-e100-80000a98800c

2010-07-06T11:55:15Z

ERP_GTPSRM_ECC6_S1

EDG_030_BusinessSystem

...

In my original post, it was the other way around. That xslt code worked in EditiX, but not PI. Before I close this post, do you have any idea why the difference?

Former Member
0 Kudos

HI Stefen,

I had one XSL question,i have seen in the blogs you have given correct answers regarding the XSLT.

My requirement is  the source file is :

<?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" encoding="UTF-8"/>

<ns0:Esri_Identify

xmlns:ns0="http://ottawa.ca/ecc/esri/ecctoesri">

   <Identify>

      <MapDescription>

         <Name/>

         <Rotation/>

      </MapDescription>

      <MapImageDisplay>

         <ImageHeight/>

         <ImageWidth/>

         <ImageDPI/>

      </MapImageDisplay>

      <SearchShape>

         <X/>

         <Y/>

      </SearchShape>

      <Tolerance/>

      <IdentifyOption/>

      <LayerIDs>

         <Int/>

      </LayerIDs>

   </Identify>

</ns0:Esri_Identify>

and expected is :

<?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" encoding="UTF-8"/>

<ns0:Esri_Identify

xmlns:ns0="http://ottawa.ca/ecc/esri/ecctoesri">

   <Identify>

      <MapDescription>

         <Name/>

         <Rotation/>

      </MapDescription>

      <MapImageDisplay>

         <ImageHeight/>

         <ImageWidth/>

         <ImageDPI/>

      </MapImageDisplay>

     <SearchShape xmlns:q4="http://www.esri.com/schemas/ArcGIS/10.0" xsi:type="q4:PointN" xmlns="">

         <X/>

         <Y/>

      </SearchShape>

      <Tolerance/>

      <IdentifyOption/>

      <LayerIDs>

         <Int/>

      </LayerIDs>

   </Identify>

</ns0:Esri_Identify>

I need to pass the name space for searchshape element, can you please help me in this regard.

Thanks,

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Keith,

Did you try to add the XMLAnonymizerBean in your communication channel:

/people/stefan.grube/blog/2007/02/02/remove-namespace-prefix-or-change-xml-encoding-with-the-xmlanonymizerbean

Regards,

---Satish

Former Member
0 Kudos

I checked into it. I read that it is recommended to use XSLT when adding a namespace. I am also using XI channel as receiver, and module tab not editable for them.