0

I want to remove the declaration in output XML. Tried using the "exclude-result-prefixes" but it didn't do anything.

my output:

<DocumentHeader>
    <SchemaName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">AcmeCorp_MotorApplicationRequest</SchemaName>
    <SchemaVersion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">v1_0</SchemaVersion>
</DocumentHeader>

Desired output:

<DocumentHeader>
    <SchemaName 
 xsi:type="xsd:string">AcmeCorp_MotorApplicationRequest</SchemaName>
    <SchemaVersion xsi:type="xsd:string">v1_0</SchemaVersion>
</DocumentHeader>

My XSLT:

<?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">
    <xsl:output method="xml"/>
    <xsl:template match="/">
        <xsl:element name="DocumentHeader">
            <xsl:element name="SchemaName">
                <xsl:attribute name="xsi:type">xsd:string</xsl:attribute>
                <xsl:attribute name="SchemaName">
                    <xsl:value-of select="/ApplicationBatch/DocumentHeader/SchemaName"/>
                </xsl:attribute>
                <xsl:value-of select="/ApplicationBatch/DocumentHeader/SchemaName"/>
            </xsl:element>
            <xsl:element name="SchemaVersion">
                <xsl:attribute name="xsi:type">xsd:string</xsl:attribute>
                <xsl:value-of select="/ApplicationBatch/DocumentHeader/SchemaVersion"/>
            </xsl:element>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>
  • The desired output with `xsi:type` attributes using a prefixed named without having any namespace declaration for that prefix is not namespace well-formed XML so it is not something XML with its serialization method for XML can generate and I can't see any reason to generate something like that as no XML parser/tool will be able to process it any further. You could move the namespace declaration to the root element by simply using `...` in your XSLT. – Martin Honnen Jul 31 '18 at 08:56
  • Thank u Martin but i didn't quiet understand what you meant. – Haris Asad Bajwa Jul 31 '18 at 12:06
  • i need to make changes in the XSLT – Haris Asad Bajwa Jul 31 '18 at 12:07
  • 1
    What you have posted as the "Desired output" is not namespace well-formed XML according to the https://www.w3.org/TR/xml-names/ specification which specifies in https://www.w3.org/TR/xml-names/#ns-using "The namespace prefix [...] MUST have been declared in a namespace declaration attribute". So having `xsi:type="xsd:string"` without having a namespace declaration for the `xsi` prefix is not allowed in XML (with namespaces). XSLT creates XML with namespaces and you will have a hard time to use it to output something that doesn't comply with the spec. – Martin Honnen Jul 31 '18 at 12:13
  • Thank you Martin... Identified the error – Haris Asad Bajwa Aug 01 '18 at 06:12

0 Answers0