My requirement is to convert below xml file :
<?xml version="1.0" encoding="UTF-8"?>
<JEES_SSI>
<P_VAT_ID>10122</P_VAT_ID>
<LIST_G_LE_DETAILS>
<G_LE_DETAILS>
<ENTITYNAME>LE NAME</ENTITYNAME>
<TAXPAYEID>A0000000A</TAXPAYEID>
</G_LE_DETAILS>
</LIST_G_LE_DETAILS>
</JEES_SSI>
To new xml file :(The required output:)
<?xml version="1.0" encoding="UTF-8"?>
<siiLR:SuministroLRFacturasRecibidas
xmlns:siiLR="https:/www.firstschema/SLR.xsd"
xmlns:sii="https://www.secondschema/sinfo.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.firstschema/ SLR.xsd">
<sii:Cabecera>
<sii:Titular>
<sii:NombreRazon>LE NAME</sii:NombreRazon>
<sii:NIF>A0000000A</sii:NIF>
</sii:Titular>
</sii:Cabecera>
</siiLR:SuministroLRFacturasRecibidas>
And i am using below XSL:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:siiLR="https:/www.firstschema/SLR.xsd"
xmlns:sii="https://www.secondschema/sinfo.xsd"
exclude-result-prefixes="sii">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xsl:element name="siiLR:SuministroLRFacturasRecibidas">
<xsl:attribute name="xmlns:siiLR"> <xsl:value-of select= "'https:/www.firstschema/SLR.xsd'" /></xsl:attribute>
<xsl:attribute name="xmlns:sii"> <xsl:value-of select= "'https://www.secondschema/sinfo.xsd'"/></xsl:attribute>
<xsl:attribute name="xsi:schemaLocation"> <xsl:value-of select= "'https://www.secondschema/ sinfo.xsd'" /> </xsl:attribute>
<xsl:element name="sii:Cabecera">
<xsl:element name="sii:Titular">
<xsl:element name="sii:NombreRazon"> <xsl:value-of select= "JEES_SSI/LIST_G_LE_DETAILS/G_LE_DETAILS/ENTITYNAME" /> </xsl:element>
<xsl:element name="sii:NIF"> <xsl:value-of select= "JEES_SSI/LIST_G_LE_DETAILS/G_LE_DETAILS/TAXPAYERID" /> </xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
Output i got:
Output is having additional string for xmlns:xmlns="http://www.w3.org/2000/xmlns/" which is causing error: XML Parsing Error: reserved prefix (xmlns) must not be declared or undeclared and namespace is getting added for first element of sii namespace.
<?xml version = '1.0' encoding = 'UTF-8'?>
<siiLR:SuministroLRFacturasRecibidas xmlns:siiLR="https:/www.firstschema/SLR.xsd"
xmlns:xmlns="http://www.w3.org/2000/xmlns/"
xmlns:sii="https://www.secondschema/sinfo.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.firstschema/ SLR.xsd">
<sii:Cabecera xmlns:sii="https://www.secondschema/sinfo.xsd">
<sii:Titular>
<sii:NombreRazon>LE NAME</sii:NombreRazon>
<sii:NIF>A0000000A</sii:NIF>
</sii:Titular>
</sii:Cabecera>
</siiLR:SuministroLRFacturasRecibidas>
Please help to correct the xsl file to get desired xml output file. There are two different namespace prefix(siiLr and sii) used for elements in xml file. exclude-result-prefixes="sii" is not excluding the namespace URI from sii:Cabecera
Modiifed XLS (implementaing suggestion @Stefan Hegny suggestion: Issue:xmlns:xmlns="http://www.w3.org/2000/xmlns/" is no longer appearing if i use below XSL.(Removing xmlns:siiLR and xmlns:sii attributes from root element)
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:siiLR="https:/www.firstschema/SLR.xsd"
xmlns:sii="https://www.secondschema/sinfo.xsd"
>
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xsl:element name="siiLR:SuministroLRFacturasRecibidas">
<xsl:attribute name="xsi:schemaLocation"> <xsl:value-of select= "'https://www.secondschema/ sinfo.xsd'" /> </xsl:attribute>
<xsl:element name="sii:Cabecera">
<xsl:element name="sii:Titular">
<xsl:element name="sii:NombreRazon"> <xsl:value-of select= "JEES_SSI/LIST_G_LE_DETAILS/G_LE_DETAILS/ENTITYNAME" /> </xsl:element>
<xsl:element name="sii:NIF"> <xsl:value-of select= "JEES_SSI/LIST_G_LE_DETAILS/G_LE_DETAILS/TAXPAYERID" /> </xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
New output using above XLS:
<?xml version = '1.0' encoding = 'UTF-8'?>
<siiLR:SuministroLRFacturasRecibidas xmlns:siiLR="https:/www.firstschema/SLR.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.firstschema/ SLR.xsd">
<sii:Cabecera xmlns:sii="https://www.secondschema/sinfo.xsd">
<sii:Titular>
<sii:NombreRazon>LE NAME</sii:NombreRazon>
<sii:NIF>A0000000A</sii:NIF>
</sii:Titular>
</sii:Cabecera>
</siiLR:SuministroLRFacturasRecibidas>
Namespace sii link is appearing in element"Cabecera". It should appear in the root element SuministroLRFacturasRecibidas