微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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/">

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。