Been trying all day to simply add an xmlns
attribute to the root element of my xml, but can't seem to get it right.
Source = A.xml
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<INPUTS>
<INP_NO_PARAM>
<OrderNbr>TR-00001541</OrderNbr>
<Priority></Priority>
<LineNbr>VPI000594422</LineNbr>
<Article>B02369</Article>
<Description>AANSLUITKLEM</Description>
<Quantity>14,00</Quantity>
<Location></Location>
<LotNbr></LotNbr>
<Comment></Comment>
<Zone>test</Zone>
<InboundCarrier></InboundCarrier>
<UnitOfMeasurement></UnitOfMeasurement>
</INP_NO_PARAM>
<INP_NO_PARAM>
<OrderNbr>TR-00001541</OrderNbr>
<Priority></Priority>
<LineNbr>VPI000594426</LineNbr>
<Article>B08432</Article>
<Description>AARDINGSKLEM</Description>
<Quantity>321,00</Quantity>
<Location></Location>
<LotNbr></LotNbr>
<Comment></Comment>
<Zone></Zone>
<InboundCarrier></InboundCarrier>
<UnitOfMeasurement></UnitOfMeasurement>
</INP_NO_PARAM>
</INPUTS>
Desired result = B.xml
<INPUTS xmlns="GE_Schemas">
<INP_NO_PARAM>
<OrderNbr>TR-00001541</OrderNbr>
<Priority></Priority>
<LineNbr>VPI000594422</LineNbr>
<Article>B02369</Article>
<Description>AANSLUITKLEM</Description>
<Quantity>14,00</Quantity>
<Location></Location>
<LotNbr></LotNbr>
<Comment></Comment>
<Zone></Zone>
<InboundCarrier></InboundCarrier>
<UnitOfMeasurement></UnitOfMeasurement>
</INP_NO_PARAM>
<INP_NO_PARAM>
<OrderNbr>TR-00001541</OrderNbr>
<Priority></Priority>
<LineNbr>VPI000594426</LineNbr>
<Article>B08432</Article>
<Description>AARDINGSKLEM</Description>
<Quantity>321,00</Quantity>
<Location></Location>
<LotNbr></LotNbr>
<Comment></Comment>
<Zone></Zone>
<InboundCarrier></InboundCarrier>
<UnitOfMeasurement></UnitOfMeasurement>
</INP_NO_PARAM>
</INPUTS>
My best attempt to achieve this result is this xsd:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
<!--No xml declaration line-->
<xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
<!-- copy everything as-is except for more specific templates below -->
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<!--Change INPUTS tag-->
<xsl:template match="INPUTS">
<INPUTS xmlns="GE_Schemas" >
</INPUTS>
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
This is the result.
Not entirely correct, because it seems to self-close the <INPUTS>
tag, while I'd like it to appear on the last line of the output:
<INPUTS xmlns="GE_Schemas"/>
<INP_NO_PARAM>
<OrderNbr>TR-00001541</OrderNbr>
<Priority/>
<LineNbr>VPI000594422</LineNbr>
<Article>B02369</Article>
<Description>AANSLUITKLEM</Description>
<Quantity>14,00</Quantity>
<Location/>
<LotNbr/>
<Comment/>
<Zone>test</Zone>
<InboundCarrier/>
<UnitOfMeasurement/>
</INP_NO_PARAM>
<INP_NO_PARAM>
<OrderNbr>TR-00001541</OrderNbr>
<Priority/>
<LineNbr>VPI000594426</LineNbr>
<Article>B08432</Article>
<Description>AARDINGSKLEM</Description>
<Quantity>321,00</Quantity>
<Location/>
<LotNbr/>
<Comment/>
<Zone/>
<InboundCarrier/>
<UnitOfMeasurement/>
</INP_NO_PARAM>
I've succeeded to remove this line
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
However, I just cannot seem to add the xmlns="GE_Schemas"
attribute to the root <INPUTS>
tag.
It's also important to keep the tags NOT self-closing.
So <Zone></Zone>
must stay that way, and cannot be changed to <Zone/>
as is also the case right now.
Does anyone have an idea how to solve these 2 issues?