从输出中省略不需要的名称空间 [英] Omit unneeded namespaces from the output

查看:83
本文介绍了从输出中省略不需要的名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的XSLT输出了一些带有xmlns:x="http://something"属性的标签...如何避免此冗余属性?输出XML永远不会在x:tagx:attribute中使用.

My XSLT is outputiung some tags with xmlns:x="http://something" attribute... How to avoid this redundant attribute? The output XML never use, neither in a the x:tag, nor in an x:attribute.

XML示例:

<root><p>Hello</p><p>world</p></root>

XSL示例:

<xsl:transform version="1.0" 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
   xmlns:xlink="http://www.w3.org/1999/xlink">
<xsl:output encoding="UTF-8" method="xml" version="1.0" indent="no"/>

<xsl:template match="root"><foo>
   <xsl:for-each select="p">
    <p><xsl:value-of select="." /></p>
   </xsl:for-each></foo>
   <xsl:for-each select="x">
    <link xlink:href="{x}" />
   </xsl:for-each></foo>
</xsl:template>

XML输出示例:

<foo>
   <p xmlns:xlink="http://www.w3.org/1999/xlink">Hello</p>
   <p xmlns:xlink="http://www.w3.org/1999/xlink">world</p>
</foo>

xmlns:xlink是开销,不使用!

典型情况,其中XSLT必须使用名称空间,但输出不使用:

A typical case where XSLT must use namespace but the output not:

 <xsl:value-of select="php:function('regFunction', . )" />

推荐答案

正如Dimitre所说,如果您不在XSLT的任何地方使用xlink命名空间,则应删除其命名空间声明.但是,如果您的XSLT实际上是在您未向我们展示的地方使用它,则可以使用exclude-result-prefixes属性来阻止将其输出:

As Dimitre has already said, if you are not using the xlink namespace anywhere in your XSLT, you should just remove its namespace declaration. If, however, your XSLT is actually using it somewhere that you haven't shown us, you can prevent it from being output by using the exclude-result-prefixes attribute:

<xsl:transform version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   exclude-result-prefixes="xlink">

这篇关于从输出中省略不需要的名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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