在 xslt 中复制整个节点时跳过一个元素 [英] Skip an element when copying the whole node in xslt
本文介绍了在 xslt 中复制整个节点时跳过一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从节点中跳过元素?例如,我们有节点作为 Test
,它有子元素 x
、y
、z
.我想复制整个 Test
节点,但不希望 z
元素出现在最终结果中.我们可以在 copy-of select
中使用 not()
吗?我试过了,但没有用.
Is it possible to skip an element from a node? For example we have node as Test
and it has child elements x
, y
,z
. I want to copy the whole Test
node but don't want z
element in the final result. Can we use not()
in copy-of select
? I tried but it didn't work.
谢谢.
推荐答案
不,<xsl:copy-of>
让您无法控制正在复制的内容内部发生的事情.这就是带有选择性省略的身份模板的用途:
No, <xsl:copy-of>
gives you no control over what happens inside what you are copying. That's what an identity template with selective omissions is for:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<!-- Identity template -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*">
<xsl:apply-templates select="Test" />
</xsl:template>
<!-- Omit z from the results-->
<xsl:template match="z" />
</xsl:stylesheet>
应用于此 XML 时:
When applied to this XML:
<n>
<Test>
<x>Hello</x>
<y>Heeelo</y>
<z>Hullo</z>
</Test>
</n>
结果是:
<Test>
<x>Hello</x>
<y>Heeelo</y>
</Test>
这篇关于在 xslt 中复制整个节点时跳过一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文