A
Adam Barr
I have a tag foo that I want to copy unchanged when it is a subtag of
bar, so I have a template (x is the namespace for the document):
<xsl:template match="x:bar/x:foo">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
BUT, I discovered that someone has been mis-speling foo as foop in the
source files. So I add another template to fix this up:
<xsl:template match="x:bar/x:foop">
<foo>
<xsl:apply-templates/>
</foo>
</xsl:template>
The problem is that the output now has xmlns attributes added to the
foo tag that I output. If the input spells "foo" correctly, matching
the first template above, this doesn't happen.
I read in the docs that <xsl:copy> copies the namespace nodes, and I
surmise that the fact that this is not done when I specify the
explicit "<foo>" output is the reason for the xmlns attributes showing
up. However, I can't figure out how to copy the namespace nodes. I try
things such as
<xsl:for-each select="namespace::*">
<xsl:copy/>
</xsl:for-each>
or
<xsl:copy-of select="namespace::*"/>
but nothing seems to work (and it's not clear where exactly to put
these). Changing <foo> to <xsl:element name="foo"> doesn't help
either.
The actual xmlns attribute varies between Microsoft's .Net XSLT (which
outputs xmlns="") and Xalan (which outputs xmlns:x="[the URI for x]"
xmlns="[the URI for x]". But what I want is no xlmns attributes at
all, as it appears when the "foo" tag is copied by <xsl:copy>. Can
this be done?
Thanks.
- adam
bar, so I have a template (x is the namespace for the document):
<xsl:template match="x:bar/x:foo">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
BUT, I discovered that someone has been mis-speling foo as foop in the
source files. So I add another template to fix this up:
<xsl:template match="x:bar/x:foop">
<foo>
<xsl:apply-templates/>
</foo>
</xsl:template>
The problem is that the output now has xmlns attributes added to the
foo tag that I output. If the input spells "foo" correctly, matching
the first template above, this doesn't happen.
I read in the docs that <xsl:copy> copies the namespace nodes, and I
surmise that the fact that this is not done when I specify the
explicit "<foo>" output is the reason for the xmlns attributes showing
up. However, I can't figure out how to copy the namespace nodes. I try
things such as
<xsl:for-each select="namespace::*">
<xsl:copy/>
</xsl:for-each>
or
<xsl:copy-of select="namespace::*"/>
but nothing seems to work (and it's not clear where exactly to put
these). Changing <foo> to <xsl:element name="foo"> doesn't help
either.
The actual xmlns attribute varies between Microsoft's .Net XSLT (which
outputs xmlns="") and Xalan (which outputs xmlns:x="[the URI for x]"
xmlns="[the URI for x]". But what I want is no xlmns attributes at
all, as it appears when the "foo" tag is copied by <xsl:copy>. Can
this be done?
Thanks.
- adam