Monday, December 01, 2008

Remove namespaces in OSB and BPEL/ESB

Removing name spaces from your XML payload is sometimes needed. Various reasons require this. This article shows you how to remove namesapces in your XML payload. There are two solutions.

XML Stylesheets (XSLT)

For BPEL and ESB you can use the XSLT solution to remove namespaces. The next example show you how to implement this in BPEL. First of all we need to create a XSLT file. The file shoudl looks like this:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl=""
<xsl:template match="comment()|processing-instruction()|/">
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
<xsl:template match="@*">
<xsl:when test="name() != 'xmlns'">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
The BPEL code to call this XSLT is as follows.

<assign name="Transform_1">
<from expression="ora:getContentAsString(
, bpws:getVariableData('inputVariable','payload'))
<to variable="outputVariable" part="payload"

The above example will remove the namespaces from the input payload, then it will convert it to a string and put the output into the result element.


The solution for OSB can alo apply via XLST, but in OSB the XQuery technology is used.. Removing the namespace in XQuery is done via the following function.

declare namespace xf = "";

declare function xf:strip-namespace($e as element())
as element()
element { xs:QName(local-name($e)) }
for $child in $e/(@*,node())
if ($child instance of element())
then xf:strip-namespace($child)
else $child
You can call this function in your XQuery file as follows.
concat('<?xml version="1.0" encoding="UTF-8"?>', fn-bea:serialize(xf:strip-namespace($varMessage)))

Post a Comment