I have xml input, in my xsl I call the template. The first tag inside the template displays with an empty xmlns attribute, as shown below.
<Section xmlns="">
Can this attribute be removed in xslt?
Please help me with this.
I just add a sample of my code,
Input.xml:
<?xml version="1.0" encoding="utf-8"?>
<List>
<Sections>
<Section>
<Column>a</Column>
<Column>b</Column>
<Column>c</Column>
<Column>d</Column>
<Column>e</Column>
</Section>
</Sections>
</List>
Stylesheet.xsl
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="List">
<report xmlns="http://developer.com/">
<Views>
<xsl:call-template name="Page"/>
</Views>
</report>
</xsl:template>
<xsl:template name="Page">
<Content>
<xsl:for-each select="./Sections/Section">
<Columns>
<xsl:for-each select="./Column">
<Column>
<xsl:attribute name="value">
<xsl:value-of select="."/>
</xsl:attribute>
</Column>
</xsl:for-each>
</Columns>
</xsl:for-each>
</Content>
</xsl:template>
The sample output.xml looks like
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://developer.com/">
<Views>
<Content xmlns="">
<Columns>
<Column value="a"/>
<Column value="b"/>
<Column value="c"/>
<Column value="d"/>
<Column value="e"/>
</Columns>
</Content>
</Views>
I need the xmlns attribute in the tag <report>, but not in the tag <Content>. This xmlns attribute is due to the fact that I called the template, and the first tag of this template is added with this attribute.
source
share