【问题标题】:how to remove a unneeded namespace declaration from xml element with xslt?如何使用 xslt 从 xml 元素中删除不需要的命名空间声明?
【发布时间】:2015-01-26 23:20:46
【问题描述】:

关于抑制不需要的命名空间声明的问题可能很简单。

  <table xmlns:new="http://ns.namespaces4all.com/xmlcombine/new"    
   xml:base="file:///R:/example/Sample.xml" frame="all">
    <tgroup cols="2">
        <colspec colname="c1"/>
        <colspec colname="c2"/>
        <tbody>
          <row>
            <entry>
              <m:math xmlns:m="http://www.w3.org/1998/Math/MathML" display="block">
              <m:mrow>
                 <m:mi>x</m:mi>

我只想删除不需要的命名空间xmlns:new,我想保留xmlns:m,但是exclude-result-prefixes="new "extension-element-prefixes="new" 删除它。 还有什么可以压制它? 最好的问候

马库斯

【问题讨论】:

  • 请发布一个最小但完整的 XML 和 XSLT 示例(+ 表示 XSLT 1.0 或 2.0)。
  • 你为什么需要exclude-result-prefixes以外的东西?
  • @MathiasMüller exclude-result-prefixes 不会在复制带有它们(或其后代)的元素时删除未使用的命名空间声明。
  • @michael.hor257k 是的,那么copy-namespaces="no" 可能会有所帮助——但我们还不知道......
  • @MathiasMüller 在 XSLT 2.0 中会这样。

标签: xml xslt namespaces


【解决方案1】:

希望这会有所帮助,

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                exclude-result-prefixes="msxsl"
                version="1.0">

使用此 exclude-result-prefixes="msxsl" 指定您不需要的命名空间

【讨论】:

  • exclude-result-prefixes 已在问题中提及。问题是:“还有什么可以压制它?” (即使我不知道为什么 OP 会问它)。此外,您至少应该修改随机​​代码 sn-p 以排除 xmlns:new 而不是 xmlns:msxsl
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-16
  • 1970-01-01
  • 2011-07-13
  • 1970-01-01
相关资源
最近更新 更多