【问题标题】:XSLT injects unwanted namespace in output fileXSLT 在输出文件中注入不需要的命名空间
【发布时间】:2011-02-11 20:16:28
【问题描述】:

我见过类似的问题,但我仍然不清楚。我不希望“n1”命名空间出现在输出文件中节点的属性中。但我必须在 xslt 文件中创建“n1”命名空间才能使 xpath 工作。谢谢。

XSLT:

   <xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:n1="http://www.spicefactory.org/parsley"
        xmlns="http://www.spicefactory.org/parsley"
        >

    <xsl:output method="xml" indent="no"/>

    <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>

     <xsl:template match="n1:object[@type='mytype1']">
      <object  type="mytype2">
        <xsl:apply-templates select="node()"/>
      </object>
     </xsl:template>

输出 XML 文件的摘录:

<object type="mytype2" xmlns:n1="http://www.spicefactory.org/parsley">

【问题讨论】:

    标签: xml xslt xml-namespaces


    【解决方案1】:

    &lt;xsl:stylesheet&gt; 元素上使用exclude-result-prefixes 属性。

    <xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:n1="http://www.spicefactory.org/parsley"
        xmlns="http://www.spicefactory.org/parsley"
        exclude-result-prefixes="n1"
        >
    

    【讨论】:

      猜你喜欢
      • 2020-09-10
      • 2013-03-13
      • 2011-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多