XSL:避免将命名空间定义导出到生成的 XML 文档 [英] XSL: Avoid exporting namespace definitions to resulting XML documents

查看:23
本文介绍了XSL:避免将命名空间定义导出到生成的 XML 文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一些 XML 文件中获取数据并将它们转换为一个新的 XML 文档.但是,我不希望 XSLT 中的名称空间定义出现在结果文档中.

I'd like to take data from some XML files and transform them into a new XML document. However, I do not want the definition of a namespace in the XSLT to occur in the result document.

换句话说:

来源:

<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 进行转换.

I am using msxsl for the transformation.

推荐答案

您可以使用 xsl:stylesheet 元素的 exclude-result-prefixes 属性来避免发出命名空间前缀到输出文档中:

You can use the exclude-result-prefixes attribute of the xsl:stylesheet element to avoid emitting namespace prefixes into the output document:

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

</xsl:stylesheet>

要禁止输出文档中的多个命名空间,请指定它们以空格分隔:

To suppress multiple namespaces from the output document specify them separated by whitespace:

exclude-result-prefixes="prefix1 prefix2 prefix3"

来自 XSLT 规范:

当样式表使用命名空间声明仅用于寻址源树时,在 exclude-result-prefixes 属性中指定前缀将避免结果树中多余的命名空间声明.

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.

这篇关于XSL:避免将命名空间定义导出到生成的 XML 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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