Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XSLT: namespace getting added in first element of each group

Ra#Ul-OracleMar 28 2017 — edited Mar 28 2017

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 :

  <?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.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 25 2017
Added on Mar 28 2017
1 comment
2,066 views