Skip to Content

XSLT in SAP: namespace issue

Jul 20, 2017 at 01:49 PM


avatar image

Dear experts!

I'm new to XSLT.

I'm trying to create a transformation which would remove a certain tag from an XML file. The tag I'm trying to remove has a namespace declaration. The idea is to get out of the following input:

<code><?xml version="1.0" encoding="utf-8"?><br><ToBeRemovedxlmns:prx="urn:something"><br><n0:ToRemainxlmns:n0=""><br><Data>

the following:

<code><?xml version="1.0" encoding="utf-8"?><br><n0:ToRemainxlmns:n0=""><Data>

I'm using the following XSLT:




Unfortunately, the namespace declaration from doesn't get completely deleted, but "sticks" somehow to the next tag :

<code><?xml version="1.0" encoding="utf-8"?><br><n0:ToRemainxlmns:n0=""<br>xlmns:prx="urn:something">


Any ideas?



10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

avatar image
Former Member Jul 21, 2017 at 01:51 PM

Hi Alexander,

this is because of the declaration of the namespace of <ToBeRemoved>. <ToRemain> inherits the namespace of <ToBeRemoved>, as <ToBeRemoved> has no namespace prefix. So, <ToRemain> has had the namespace before, but inherited and not declared. This thread explains this behaviour quite good from another perspective:

So the output XML is right by definition. I hope this helps.

Kind regards

10 |10000 characters needed characters left characters exceeded
Evgeniy Kolmakov Mar 05 at 12:57 PM

Hi Alexander!

In this case you should use recursive template to create new elements with same names and data instead of copying the original elements.

As Moritz has already mentioned when you copy element from source tree - you copy it together with namespace info which is inherited from parent element.

Regrads, Evgeniy.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

One more thought: if your XSL transformation is intended just to remove unwanted namespace from XML document - maybe you could give XMLAnonymizerBean a try?

Regards, Evgeniy.