XSLT - 忽略/删除子节点中的空命名空间 [英] XSLT - Ignore/Remove the empty namespace in the child node

查看:38
本文介绍了XSLT - 忽略/删除子节点中的空命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了能够拥有一个带有 dynamic 命名空间值的 root 元素,我将其从:<Foo xmlns="HardCodedXMLNS"> 到:

当前的 XSLT 看起来像这样:

现在的问题是 <Bar> 元素在转换后得到一个空的命名空间,像这样(当前输出):

<Bar xmlns=""></酒吧></Foo>

预期输出:

<酒吧></酒吧></Foo>

问题:如何解决这个问题,使得 Bar 节点没有命名空间?

解决方案

一般来说,原则是:如果你把元素放在正确的命名空间中,命名空间声明会照顾好自己.您对子元素有 xmlns="" 声明的原因是您将子元素创建为无命名空间元素.

(如果您想在答案中使用实际代码,请在问题中添加一些代码.特别是,您的标题谈到了动态设置命名空间,但您还没有说明它是否真的需要是动态的).

In order to be able to be able to have a root element with a dynamic namespace value I switched it from: <Foo xmlns="HardCodedXMLNS"> to: <xsl:element name="Foo" namespace="{Table/Foo_Dynamic_XMLNS}">

The current XSLT looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" />
    <xsl:template match="/NewDataSet">
        <xsl:element name="Foo" namespace="{Table/Foo_xmlns}">
            <Bar Id ="{Table/Bar_Id}">
            </Bar>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

Now the problem is that the <Bar> element gets an empty namespace after transformation like this (Current output):

<Foo xmlns="http://MyDynamicValue">
    <Bar xmlns="">
    </Bar>
</Foo>

Expected output:

<Foo xmlns="http://MyDynamicValue">
    <Bar>
    </Bar>
</Foo>

Question: How would one solve this problem so that the Bar node doesn't have the namespace?

解决方案

Generally, the principle is: if you put the elements in the right namespace, the namespace declarations will look after themselves. The reason you have an xmlns="" declaration on the child is that you created the child element as a no-namespace element.

(If you want actual code in the answer, then put some code in the question. In particular, your title talks about setting the namespace dynamically, but you haven't explained whether it really needs to be dynamic).

这篇关于XSLT - 忽略/删除子节点中的空命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆