Home > database >  Added xsi:nil="true" and default namespace and it produces xmlns="" after transf
Added xsi:nil="true" and default namespace and it produces xmlns="" after transf

Time:11-23

I'm trying to add xsi:nil="true" for empty elements and default namespace to all elements.

The transform successfully reflects these namespaces but the child's child now contains a blank xmlns attribute. How can I prevent this xmlns=""?

XSLT Snippet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="@* | node()">
        <xsl:copy>            
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="*[not(text())]">
        <xsl:copy>
            <xsl:attribute name="xsi:nil">true</xsl:attribute>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="*">
        <xsl:element name="{local-name()}" namespace="http://xmlns.oracle.com/pcbpel/adapter/db/ORESB_STAAConfig_DBAdapter">
            <xsl:namespace name="xsi" select="'http://www.w3.org/2001/XMLSchema-instance'"/>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

XML:

    <ORESB_STAAConfig_DBAdapterOutput>
        <ACODE>A52557</ACODE>
        <DESC_TO_CP>WLR ISDN2E System</DESC_TO_CP>
        <TYPE>EX</TYPE>
        <INSTALLATION_TYPE>Standard</INSTALLATION_TYPE>
        <PAYPHONE_TYPE/>
        <TERMINATION_TYPE>NTE</TERMINATION_TYPE>
    </ORESB_STAAConfig_DBAdapterOutput>
    <ORESB_STAAConfig_DBAdapterOutput>
        <ACODE>A52558</ACODE>
        <DESC_TO_CP>WLR ISDN2E System</DESC_TO_CP>
        <TYPE>EX</TYPE>
        <INSTALLATION_TYPE>Standard</INSTALLATION_TYPE>
        <PAYPHONE_TYPE/>
        <TERMINATION_TYPE>NTE</TERMINATION_TYPE>
    </ORESB_STAAConfig_DBAdapterOutput>
</ORESB_STAAConfig_DBAdapterOutputCollection>

Resulting XML:

<ORESB_STAAConfig_DBAdapterOutputCollection xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/ORESB_STAAConfig_DBAdapter"
                                            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ORESB_STAAConfig_DBAdapterOutput>
        <ACODE>A52557</ACODE>
        <DESC_TO_CP>WLR ISDN2E System</DESC_TO_CP>
        <TYPE>EX</TYPE>
        <INSTALLATION_TYPE>Standard</INSTALLATION_TYPE>
        <PAYPHONE_TYPE xmlns="" xsi:nil="true"/>
        <TERMINATION_TYPE>NTE</TERMINATION_TYPE>
    </ORESB_STAAConfig_DBAdapterOutput>
    <ORESB_STAAConfig_DBAdapterOutput>
        <ACODE>A52558</ACODE>
        <DESC_TO_CP>WLR ISDN2E System</DESC_TO_CP>
        <TYPE>EX</TYPE>
        <INSTALLATION_TYPE>Standard</INSTALLATION_TYPE>
        <PAYPHONE_TYPE xmlns="" xsi:nil="true"/>
        <TERMINATION_TYPE>NTE</TERMINATION_TYPE>
    </ORESB_STAAConfig_DBAdapterOutput>
</ORESB_STAAConfig_DBAdapterOutputCollection>

CodePudding user response:

If you want to change the namespace for all elements then you can't use xsl:copy in

<xsl:template match="*[not(text())]">
    <xsl:copy>

but need

<xsl:template match="*[not(text())]">
     <xsl:element name="{local-name()}" namespace="http://xmlns.oracle.com/pcbpel/adapter/db/ORESB_STAAConfig_DBAdapter">
  • Related