Skip to Content

XSLT in SAP: namespace issue

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?



Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • 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

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 05, 2018 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.

    Add comment
    10|10000 characters needed 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.