如何在XSLT 1.0中模仿copy-namespaces ="no"?

Nes*_*tor 9 xml xslt

我想在XSLT 1.0中重写这个xslt片段,它不支持"copy-namespaces".

<xsl:copy-of copy-namespaces="no" select="maml:alertSet/maml:alert" />
Run Code Online (Sandbox Code Playgroud)

怎么样?

Mic*_*Kay 13

以下模仿XSLT 2.0构造:

以一种模式创建模板,该模式将重新构建没有名称空间的节点:

<!-- generate a new element in the same namespace as the matched element,
     copying its attributes, but without copying its unused namespace nodes,
     then continue processing content in the "copy-no-namepaces" mode -->

<xsl:template match="*" mode="copy-no-namespaces">
    <xsl:element name="{local-name()}" namespace="{namespace-uri()}">
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates select="node()" mode="copy-no-namespaces"/>
    </xsl:element>
</xsl:template>

<xsl:template match="comment()| processing-instruction()" mode="copy-no-namespaces">
    <xsl:copy/>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

在该模式下为所需元素应用模板:

<xsl:apply-templates  select="maml:alertSet/maml:alert" mode="copy-no-namespaces"/>
Run Code Online (Sandbox Code Playgroud)