xslt – 从输出xml中删除空xmlns命名空间

前端之家收集整理的这篇文章主要介绍了xslt – 从输出xml中删除空xmlns命名空间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个输入xml,在我的xsl中我调用了一个模板.模板内的第一个标签显示为空的xmlns属性,如下所示

<Section xmlns="">

可以在xslt中消除此属性吗?

请在这件事上给予我帮助..

我只是添加了我的代码示例,

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>

output.xml看起来像

<?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>

我需要< report>中的xmlns属性标签但不在< Content>中标签.这个xmlns属性的出现是因为我调用了一个模板,并且该模板的第一个标记添加了该属性.

解决方法

在XSLT中向Content添加名称空间:

<xsl:template name="Page">
    <Content xmlns="http://developer.com/">

猜你在找的XML相关文章