I want to map the root element "FOO" and perform the conversion (add the version attribute) to it, leaving the rest as it is. The transformation that I still looked like this:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://schemas.foo.com/fooNameSpace">
<xsl:template match="//FOO">
<xsl:choose>
<xsl:when test="@version">
<xsl:apply-templates select="node()|@*" />
</xsl:when>
<xsl:otherwise>
<FOO>
<xsl:attribute name="version">1</xsl:attribute>
<xsl:apply-templates select="node()|@*" />
</FOO>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
However, this does not perform any conversion. It does not even detect an element. Therefore, I need to add a namespace to make it work:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fd="http://schemas.foo.com/fooNameSpace">
<xsl:template match="//fd:FOO">
…
But this associates the namespace attribute with the FOO element, as well as with other elements:
<FOO xmlns:fd="http://schemas.foo.com/fooNameSpace" version="1" id="fooid">
<BAR xmlns="http://schemas.foo.com/fooNameSpace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- Is there a way to say that an element uses the default namespace?
- Can we map and add elements to the default namespace?
Here is the original XML:
<?xml version="1.0" encoding="UTF-8"?>
<FOO xmlns="http://schemas.foo.com/fooNameSpace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<BAR>
<Attribute name="HEIGHT">2067</Attribute>
</BAR>
</FOO>