Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Need Help in XSLT Mapping: Remove Namespace & Prefix except one element

HI,

The source structure coming from a webservice contains xml namespace in all elements. I need to remove it from all elements except the top element. I can't use XML anonymizer bean for some reason. The structure is like:

<RecordNode xmlns="urn:xxyy:xyz">

   <Field1 xmlns="urn:xxyy:xyz"> 12000</Field1>

   <Field2 xmlns="urn:xxyy:xyz"> 900</Field2>

</RecordNode>

Thus I need to remove this section (xmlns="urn:xxyy:xyz">) from all fields i.e field1,field2,.....last field Except the top element i.e RecordNode. I could get XSLT mapping for removing all namespaces but how do I do it for the above case. Please note that after XSLT mapping, the field say field1 should look like:

<Field1>12000</Field1>

Regards,

Singh

Former Member
replied

Hi Singh,

              

The <xsl:template> element is used to build templates (or rules to apply when specific match is found).

The match attribute is used to associate a template with an XML element. The match attribute can also be used to define a template for the entire XML document. The value of the match attribute is an XPath expression. Using wildcard such as *,@*,node() can be used to select unknown XML elements. The meanings of these are shown below

WildcardDescription
*Matches any element node
@*Matches any attribute node
node()Matches any node of any kind

After root node is matched it is copied to target with its attribute,namespace and value. Then <xsl:copy> element creates a copy of the current node or the root node.

Namespace nodes of the current node are automatically copied as well, but child nodes and attributes of the current node are not automatically copied. Hence namepace information of child nodes do not flow to target XML.

Regards

Anupam

2 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question