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}
CodePudding user response:
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.
CodePudding user response:
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>