0

I am transforming input XML to this output format:

<InvoiceTransmission xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="IATAFuelInvoiceStandardv2.0.2.xsd">
  <InvoiceTransmissionHeader>
    <InvoiceCreationDate>2020-07-23</InvoiceCreationDate>
    <Version>2.0.2</Version>
  </InvoiceTransmissionHeader>
.....
</InvoiceTransmission>

And I have problem with proper setup of root element This is my XST but I am still receiving error.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">

    <xsl:output method="xml" encoding="UTF-8" standalone="no"/>

    <xsl:template match="/">        
        <!--<InvoiceTransmission xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="IATAFuelInvoiceStandardv2.0.2.xsd">-->
        <InvoiceTransmission> 
        <xsl:element name="InvoiceTransmission"> 
            <xsl:namespace name="xsi" select="'http://www.w3.org/2001/XMLSchema-instance'" />           
            <xsl:attribute name="xsi:noNamespaceSchemaLocation">
                <xsl:value-of select="IATAFuelInvoiceStandardv2.0.2.xsd" />
            </xsl:attribute>
        </xsl:element>
        <xsl:apply-templates select="SSC"/>
        </InvoiceTransmission>
    </xsl:template>
</xsl:stylesheet> 

And this is error which I receive:

XTDE0860  Undeclared namespace prefix {xsi}  
1
  • While asking an XSLT question you need to provide a minimal reproducible example: (1) Input XML. (2) Your logic, and XSLT that tries to implement it. (3) Desired output, based on the sample XML in the #1 above. (4) XSLT processor and its conformance with the XSLT standards: 1.0, 2.0, 3.0, or 4.0. Commented Nov 28, 2022 at 16:27

2 Answers 2

1

The xsl:namespace statement produces a namespace node in the output - something which you probably do not need. In order to use the namespace in your XSL transformation, you must include an xmlns:xsi namespace declaration:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  exclude-result-prefixes="xs xsi" version="2.0">

Also, you probably want to replace

<xsl:attribute name="xsi:noNamespaceSchemaLocation">
  <xsl:value-of select="IATAFuelInvoiceStandardv2.0.2.xsd" />
</xsl:attribute>

with simply

<xsl:attribute name="xsi:noNamespaceSchemaLocation">IATAFuelInvoiceStandardv2.0.2.xsd</xsl:attribute>

because IATAFuelInvoiceStandardv2.0.2.xsd is not a path in your XML document.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, that helps. Now I have only one problem, in root element I have xsi:noNamespaceSchemaLocation="" instead of xsi:noNamespaceSchemaLocation="IATAFuelInvoiceStandardv2.0.2.xsd"
See my augmented answer.
xmlns:xsi is not an attribute; it's a namespace declaration.
0

Is there a reason why you cannot do simply:

<xsl:template match="/">        
    <InvoiceTransmission xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="IATAFuelInvoiceStandardv2.0.2.xsd">
       <!--  the rest of the code -->
    </InvoiceTransmission>
</xsl:template>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.