XSLT - 使用复制命名空间时,未引用的命名空间仍会传播 ="no"

标签 xslt namespaces marklogic

为什么不 copy-namespaces="no"删除未在 XSLT 的输出文档中引用的 namespace 声明?我正在使用 MarkLogic 5 XSLT 处理器。

样本输入

<root xmlns:temp="http://temp" xmlns:keep="http://keep">
  <wrapper><temp:x>A</temp:x>BC<temp:x>D</temp:x></wrapper>
  <keep:me>XYZ</keep:me>
</root>

示例 XSL
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:temp="http://temp"
  xmlns:keep="http://keep"
  exclude-result-prefixes="#all">

<xsl:template match="node()|@*" priority="-1" mode="#all">
    <xsl:copy copy-namespaces="no">
        <xsl:apply-templates select="@*|node()" mode="#current"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="temp:x">
  <xsl:apply-templates />
</xsl:template>

</xsl:stylesheet>

预期输出
<root xmlns:keep="http://keep">
  <wrapper>ABCD</wrapper>
  <keep:me>XYZ</keep:me>
</root>

实际产量
<root xmlns:temp="http://temp" xmlns:keep="http://keep">
  <wrapper>ABCD</wrapper>
  <keep:me>XYZ</keep:me>
</root>

最佳答案

我向 MarkLogic 支持人员确认这是一个错误,他们正在修复。

同时,我使用这些模板代替身份模板作为解决方法:

<xsl:template match="*" priority="-1" mode="#all">
    <xsl:element name="{name(.)}">
        <xsl:apply-templates select="@*|node()" mode="#current"/>
    </xsl:element>
</xsl:template>

<xsl:template match="@*" priority="-1" mode="#all">
    <xsl:attribute name="{name(.)}" select="."/>
</xsl:template>

<xsl:template match="comment()|processing-instruction()|text()" priority="-1" mode="#all">
    <xsl:copy/>
</xsl:template>

关于XSLT - 使用复制命名空间时,未引用的命名空间仍会传播 ="no",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12430212/

相关文章:

html - 如何使用 xslt 解码 html 字符串

c++ - 在 C++ 中的 "using namespace::X"中的前导::是什么意思

javascript - 在 MarkLogic 9 中出现 XDMP-EXPNTREECACHEFULL 错误

XSLT 字符串解析

xslt - 错误消息 : XTSE0120: No character data is allowed between top-level elements 中存在误导性行号

c++ - 限制头文件中 "using namespace"的范围

java - 使用 MarkLogic 和 Java 客户端 API 进行工作?

xml - 在 XPATH 中使用多个命名空间

html - 如何将css添加到xsl文件中?

c# Class Names - 关于如何命名类的约定