首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在XSLT 1.0中模拟copy-namespaces="no“?

如何在XSLT 1.0中模拟copy-namespaces="no“?
EN

Stack Overflow用户
提问于 2012-01-27 06:15:20
回答 1查看 11.3K关注 0票数 9

我想用xslt 1.0重写这段XSLT,它不支持"copy-namespaces“。

代码语言:javascript
复制
<xsl:copy-of copy-namespaces="no" select="maml:alertSet/maml:alert" />

多么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-27 16:50:34

下面的代码模拟了XSLT 2.0结构:

在不使用命名空间的情况下重新构建节点的模式下创建模板:

代码语言:javascript
复制
<!-- 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>

应用-该模式下所需元素的模板:

代码语言:javascript
复制
<xsl:apply-templates  select="maml:alertSet/maml:alert" mode="copy-no-namespaces"/>
票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9026224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档