Skip to Content

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

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Dec 14, 2017 at 02:27 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded