加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xslt – 没有命名空间的XML

发布时间:2020-12-16 22:50:33 所属栏目:百科 来源:网络整理
导读:我需要从信封中提取 XML.但我无法得到我想要的输出. 我需要摆脱输出中的命名空间. 我的意见: ns1:input xmlns:ns1="http://mysapmle.org/" xmlns="http://othersample.org/" sample inner tc="5"Test/inner routineAlways/routine /sample/ns1:input 我的预
我需要从信封中提取 XML.但我无法得到我想要的输出.
我需要摆脱输出中的命名空间.

我的意见:

<ns1:input xmlns:ns1="http://mysapmle.org/" xmlns="http://othersample.org/">
        <sample>
            <inner tc="5">Test</inner>
            <routine>Always</routine>
        </sample>
</ns1:input>

我的预期成果:

<sample>
    <inner tc="5">Test</inner>
    <routine>Always</routine>
</sample>

我的实际产出:

<sample xmlns="http://othersample.org/">
            <inner tc="5">Test</inner>
            <routine>Always</routine>
        </sample>

我的XSLT:

<xsl:output omit-xml-declaration="yes" indent="yes" />

<xsl:template match="/">
    <xsl:copy copy-namespaces="no">
        <xsl:apply-templates select="//sample" />           
    </xsl:copy>     
</xsl:template> 

<xsl:template match="@*|node()">
    <xsl:copy copy-namespaces="no">
        <xsl:apply-templates select="@*|node()" />          
    </xsl:copy>     
</xsl:template>

请帮忙.

解决方法

这应该用于剥离命名空间:

<xsl:output omit-xml-declaration="yes" indent="yes" />

<xsl:template match="/">
   <xsl:apply-templates select="*/*" />
</xsl:template>

<xsl:template match="@*">
    <xsl:attribute name="{local-name()}">
        <xsl:value-of select="."/>          
    </xsl:attribute>     
</xsl:template>

<xsl:template match="*">
    <xsl:element name="{local-name()}">
        <xsl:apply-templates select="@* | node()" />
    </xsl:element>
</xsl:template>

但我有点怀疑你需要这样做.如果您要将此附加到的XML使用相同的命名空间,并且这是包含XML的命名空间应该具有的,那么此XML中的命名空间声明应该无关紧要.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读