0
votes

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

Output with multiple sii element

2

2 Answers

1
votes

<xsl:attribute name="xmlns:sii"> is adding the xmlns namespace, do you really intend this??

Edit: This is not necessary as all the namespace prefixes declared at the top are inherited everywhere. Omit all those attributes xmlns:sii, xmlns:siiLR etc.

The sii Namespace is used by your created elements like <xsl:element name="sii:Cabecera">, and that's why it appears. If you do not want it create the elements without namespace like

<xsl:element name="Cabecera">

and do not copy any sii: namespace-prefixed elements into your output.

Edit 2 for the required output you show

Why would you want to exclude the sii namespace? It is used in your output and so must be in there...

I think the schema location should contain the namespace URL plus the Schema URL, no idea if you should collapse that into one if identical.

I've also simplified several of your xsl:elements that can be written simply as elements.

    <?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:text>https://www.secondschema/sinfo.xsd https://www.secondschema/sinfo.xsd</xsl:text></xsl:attribute>


    <sii:Cabecera>
                <sii:Titular> 
                    <sii:NombreRazon> <xsl:value-of select= "JEES_SSI/LIST_G_LE_DETAILS/G_LE_DETAILS/ENTITYNAME" /> </sii:NombreRazon>
                    <sii:NIF> <xsl:value-of select= "JEES_SSI/LIST_G_LE_DETAILS/G_LE_DETAILS/TAXPAYERID" /> </sii:NIF>
                </sii:Titular>
              </sii:Cabecera>     
</xsl:element> 
0
votes

Why do you want to use siiLR:SuministroLRPagosRecibidas as a xsl:element??? Instead of using :

 <xsl:element name="siiLR:SuministroLRFacturasRecibidas">

 <xsl:attribute name="xsi:schemaLocation"><xsl:text>https://www.secondschema/sinfo.xsd https://www.secondschema/sinfo.xsd</xsl:text></xsl:attribute>

....

Try the following :

xsi:schemaLocation= "https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/ssii/fact/ws/SuministroLR.xsd SuministroLR.xsd" >

I think this should resolve the issue. Let me know.