I have an XML file which has to be transformed using XSLT, I am adding a node to a subtree. The input file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Context>
<ContextExtra>
<ns3:timestampList xmlns:ns3="http://www.mydomain.com/myAdapter/basicMessage/1.0"
xmlns:ns2="http://www.mydomain.com/myAdapter/tbMessage/1.0"
xmlns="http://www.mydomain.com/myAdapter/timestamp/1.0"
xmlns:ns10="http://www.mydomain.com/myAdapter/coMessage/1.0"
xmlns:ns11="http://www.mydomain.com/myAdapter/lolMessage/1.0"
xmlns:ns12="http://www.mydomain.com/myAdapter/tcMessage/1.0"
xmlns:ns13="http://www.mydomain.com/myAdapter/bMessage/1.0"
xmlns:ns4="http://www.mydomain.com/myAdapter/tiMessage/1.0"
xmlns:ns5="http://www.myDomain.com/myAdapter/oriMessage/1.0"
xmlns:ns6="http://www.myDomain.com/myAdapter/eiMessage/1.0"
xmlns:ns7="http://www.myDomain.com/myAdapter/fplscMessage/1.0"
xmlns:ns8="http://www.myDomain.com/myAdapter/psMessage/1.0"
xmlns:ns9="http://www.myDomain.com/myAdapter/stMessage/1.0">
<timestampInfo>
<timestampID>START</timestampID>
<timestamp>2012-02-25T00:30:18.705+01:00</timestamp>
<description xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</timestampInfo>
<timestampInfo>
<timestampID>END</timestampID>
<timestamp>2012-02-25T00:30:23.675+01:00</timestamp>
<description xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</timestampInfo>
</ns3:timestampList>
</ContextExtra>
</Context>
The transformation looks like this
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:output method="xml" indent="yes" />
<xsl:param name="newTimeStamp">
<timestampInfo>
<timestampID>
<xsl:text>TEST TEST</xsl:text>
</timestampID>
<timestamp>
<xsl:text>2012-02-25T00:30:23.654+01:00</xsl:text>
</timestamp>
<description>
<xsl:text>this is a test</xsl:text>
</description>
</timestampInfo>
</xsl:param>
<xsl:template match="//ts:timestampInfo[position()=last()]">
<xsl:call-template name="identity" />
<xsl:copy-of select="$newTimeStamp" />
</xsl:template>
<xsl:template match="node()|@*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
and the result is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Envelope>
<Context>
<ContextExtra>
<ns3:timestampList xmlns="http://www.myDomain.com/myAdapter/timestamp/1.0" xmlns:ns3="http://www.myDomain.com/myAdapter/basicMessage/1.0">
<timestampInfo>
<timestampID>MTA_START</timestampID>
<timestamp>2012-02-25T00:30:18.705+01:00</timestamp>
<description xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</timestampInfo>
<timestampInfo>
<timestampID>MTA_END</timestampID>
<timestamp>2012-02-25T00:30:23.675+01:00</timestamp>
<description xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</timestampInfo>
<timestampInfo xmlns="">
<timestampID>TEST TEST</timestampID>
<timestamp>2012-02-25T00:30:23.654+01:00</timestamp>
<description>This is a test</description>
</timestampInfo>
</ns3:timestampList>
</ContextExtra>
</Context>
As you can see timestampInfo
nodes have as attribute xmlns=""
. That is, it is an empty namespace generated. Instead of <timestampInfo xmlns="">
I would like to have nodes of the form <timestampInfo>
. The input file has this format and I have no control over it.
How I can achieve this?
Thanks in advance