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

查看:88
本文介绍了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天全站免登陆