This was fixed by adding a template for the root node, which automatically added all the needed prefixes to it, with no additional change.
This is the final XSL
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:bfp="http://www.test.com/breakFixProcess/3.0/"
xmlns:dm="http://www.test.com/dataModel/3.0/"
xmlns:xmlns="http://www.w3.org/2000/xmlns/"
exclude-result-prefixes="xmlns xs">
<xsl:template match="/bfp:*">
<bfp:Message>
<xsl:apply-templates select="@* , node()"/>
</bfp:Message>
</xsl:template>
<xsl:template match="bfp:* | @bfp:*">
<xsl:element name="bfp:{local-name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates select="@* , node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="dm:*|@dm:*">
<xsl:element name="dm:{local-name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates select="@* , node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
I'm trying to find a way to include a prefix in a field, without having the xmlns prefix redefined.
I've been trying to include an additional prefix to the root element using
< xsl:attribute name="xmlns:dm">www.test.com < /xsl:attribute >
But, since XMLNS is not defined, then it adds its definition, which is processed as an attempt to redefine the xmlns prefix.
Is there a way to include this? The dm prefix is defined in my stylesheet.
This is my XSL:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:bfp="http://www.test.com/breakFixProcess/3.0/"
xmlns:dm="http://www.test.com/dataModel/3.0/"
xmlns="http://www.w3.org/2000/xmlns/"
exclude-result-prefixes="xmlns">
<xsl:template match="bfp:* | @bfp:*">
<xsl:element name="bfp:{local-name()}" >
<xsl:for-each select="@*">
<xsl:attribute name="{name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:attribute name="xmlns:dm">http://www.test.com/dataModel/3.0/</xsl:attribute>
<xsl:apply-templates select="@* , node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="dm:* | @dm:*">
<xsl:element name="dm:{local-name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates select="@* , node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Which adds the xmlns:xmlns prefix to the resulting XML.