如何在XSLT输出中保留XML名称空间? [英] How to preserve XML namespace in XSLT output?

查看:87
本文介绍了如何在XSLT输出中保留XML名称空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XSL样式表应将以下代码输出到Internet Explorer:

XSL stylesheet should output following code to Internet Explorer:

<xml:namespace prefix="vml" ns="urn:schemas-microsoft-com:vml"/>

但是当我使用任何XML执行以下模板时

But when I execute following template with any XML

<xsl:template match="*|node()">
    <xml:namespace prefix="vml"
                   ns="urn:schemas-microsoft-com:vml"/>
</xsl:template>

IE引发分析错误:样式表不包含文档元素. 同时Firefox在输出中删除 xml 命名空间...

IE throws parsing error: The stylesheet does not contain document element. In the same time Firefox removes xml namespace in the output...

那么,如何在输出中保留 xml 命名空间?

So, how can I preserve xml namespace in my output?

重要

a.我使用的输出方法是 html

a. Output method I use is html

b.以下代码无法解决我的问题:

b. Following code does not fix my problem:

<xsl:template match="*|node()">
    <namespace prefix="vml"
               xmlns="http://www.w3.org/XML/1998/namespace"
               ns="urn:schemas-microsoft-com:vml"/>
</xsl:template>

推荐答案

您不能使用保留的xml前缀.使用类似这样的内容:

You can't use the preserved xml prefix. Use something like this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dummy="dummy">
<xsl:namespace-alias stylesheet-prefix="dummy" result-prefix="xml"/>
<xsl:template match="/">
    <dummy:namespace prefix="vml"
                   ns="urn:schemas-microsoft-com:vml"/>
</xsl:template>
</xsl:stylesheet>

通过任何输入,您都会得到以下结果:

With any input, you get this result:

<xml:namespace prefix="vml" ns="urn:schemas-microsoft-com:vml" />

这篇关于如何在XSLT输出中保留XML名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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