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

XSL:避免将名称空间定义导出到生成的XML文档

发布时间:2020-12-16 08:07:24 所属栏目:百科 来源:网络整理
导读:我想从一些XML文件中获取数据,并将它们转换为一个新的XML文档。但是,我不想在结果文档中出现XSLT中的命名空间的定义。 换一种说法: 资源: Namespace:Root xmlns:Namespace="http://www.something.com" 样式表: ?xml version="1.0" encoding="ISO-8859-1
我想从一些XML文件中获取数据,并将它们转换为一个新的XML文档。但是,我不想在结果文档中出现XSLT中的命名空间的定义。

换一种说法:

资源:

<Namespace:Root xmlns:Namespace="http://www.something.com">

样式表:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:Namespace="http://www.something.com">

结果:

<resultRoot xmlns:Namespace="http://www.something.com">
<!--I don't want the Namespace definition above-->

我使用msxsl进行转换。

您可以使用xsl:stylesheet元素的exclude-result-prefixes属性来禁止输出文档中的命名空间:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:Namespace="http://www.something.com"
         exclude-result-prefixes="Namespace">

</xsl:stylesheet>

要从输出文档中删除多个命名空间,请使用空格分隔它们:

exclude-result-prefixes="ns1 ns2 ns3"

从XSLT specification:

When a stylesheet uses a namespace declaration only for the purposes of addressing the source tree,specifying the prefix in the exclude-result-prefixes attribute will avoid superfluous namespace declarations in the result tree.

(编辑:李大同)

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

    推荐文章
      热点阅读