I have the following input xml:
<?xml version='1.0' encoding='UTF-8'?>
<fde-request xmlns="http://xml-schemas.xxx.com/bb/xxx.xsd"
xmlns:cbe="http://xml-schemas.xxx.com/bb/xxx.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xml-schemas.xxx.com/bb/xxx.xsd xxx.xsd">
<cbe:request-header
user-id="mde"
session-token="433"
audit-id="9999"
pearl-code="ca"
interface-id="mf"
system-name="sr"
function-code="image"
/>
<fde-parms
function-code='b'
sccf-serial='042463452400'
type-process='H'>
</fde-parms>
</fde-request>
I need to get the following output xml by copying attribute to new element values:
<?xml version='1.0' encoding='UTF-8'?>
<fde-request xmlns="http://xml-schemas.xxx.com/bb/xxx.xsd"
xmlns:cbe="http://xml-schemas.xxx.com/bb/xxx.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xml-schemas.xxx.com/bb/xxx.xsd xxx.xsd">
<REQUEST-HEADER>
<REQUEST-ID>mde</REQUEST-ID>
<REQUEST-PEACODE>ca</REQUEST-PEACODE>
</REQUEST-HEADER>
<fde-parms
function-code='b'
sccf-serial='042463452400'
type-process='H'>
</fde-parms>
</fde-request>
BUT: I am getting this output xml with the following xslt:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="*[local-name(.)='request-header']">
<xsl:variable name="sysname" select="@system-name"/>
<xsl:variable name="peacode" select="@pearl-code"/>
<REQUEST-HEADER>
<REQUEST-ID><xsl:value-of select="$sysname"/></REQUEST-ID>
<REQUEST-PEACODE><xsl:value-of select="$peacode"/></REQUEST-PEACODE>
</REQUEST-HEADER>
</xsl:template>
</xsl:stylesheet>
That produces the wrong output: xmlns="" is populating, which is not what I want.
<?xml version='1.0' encoding='UTF-8'?>
<fde-request xmlns="http://xml-schemas.xxx.com/bb/xxx.xsd"
xmlns:cbe="http://xml-schemas.xxx.com/bb/xxx.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xml-schemas.xxx.com/bb/xxx.xsd xxx.xsd">
<REQUEST-HEADER **xmlns=""**>
<REQUEST-ID>mde</REQUEST-ID>
<REQUEST-PEACODE>ca</REQUEST-PEACODE>
</REQUEST-HEADER>
<fde-parms
function-code='b'
sccf-serial='042463452400'
type-process='H'>
</fde-parms>
</fde-request>
I need to remove this unnecessary empty namespace.
How would you modify the xslt to produce the right output?