Skip to Content
0

How to remove only xml header and not namespace after mapping in HCI

Dec 14, 2017 at 02:15 PM

187

avatar image

Hi Experts,

I have a XML file and want to remove <?xml version="1.0" encoding="UTF-8"?>

without losing ns0 from other tags.

<?xml version="1.0" encoding="UTF-8"?>
<ns0:Save xmlns:ns0="http://www.xyz.com/api/">
    <ns0:userContext>
        <ns0:IsSuccess>true</ns0:IsSuccess>
        <ns0:Message>true</ns0:Message>
    </ns0:userContext>
</ns0:Save>

when i am using XSLT mappingmentioned below,its removing all "ns0" tags as well.

So i probably need a groovy code for my HCI

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes" method="xml" encoding="utf-8" omit-xml-declaration="yes"/>
    <xsl:template match="*">
        <xsl:element name="{local-name()}">
            <xsl:apply-templates select="@* | node()"/>
        </xsl:element>
    </xsl:template>
    <xsl:template match="@*">
        <xsl:attribute name="{local-name()}">
            <xsl:value-of select="."/>
        </xsl:attribute>
    </xsl:template>
    <xsl:template match="comment() | text() | processing-instruction()">
        <xsl:copy/>
    </xsl:template>
</xsl:stylesheet>

Please help.

Thanks and Regards,

Thouheed.

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

1 Answer

Evgeniy Kolmakov Dec 14, 2017 at 02:27 PM
0

Hi Thouheed!

And why not to use:

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

You use local-name() function which returns only element name without namespace prefix.

Regards, Evgeniy.

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

Hi Evgeniy,

Thanks for quick response, i found some other solution its working fine.

Thanks and Regards,

Thouheed.

0