xsl:copy 和 xsl:copy-of 有什么区别? [英] What is the difference between xsl:copy and xsl:copy-of?

查看:41
本文介绍了xsl:copy 和 xsl:copy-of 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看不出 xsl:copyxsl:copy-of 之间的区别.

I don't see the difference between xsl:copy and xsl:copy-of.

我应该在哪种情况下使用哪个?

Which one should I use in which situation?

推荐答案

简而言之, xsl:copy 是浅拷贝;xsl:copy-of 是一个深拷贝.

In short, xsl:copy is a shallow copy; xsl:copy-of is a deep copy.

  • 使用xsl:copy当您只想复制上下文项和对上下文项的子项有其他计划.
  • 使用xsl:copy-of 当您想复制 XPath 选择的节点和他们的孩子,递归.
  • Use xsl:copy when you want to copy just the context item and have other plans for the children of the context item.
  • Use xsl:copy-of when you want to copy XPath-selected nodes and their children, recursively.
  • xsl:copy指令复制上下文项但没有其子节点.
  • 这是一个浅拷贝.
  • xsl:copy指令不能具有 @select XPath.
  • The xsl:copy instruction copies the context item but none of its children nodes.
  • This is a shallow copy.
  • The xsl:copy instruction cannot have a @select XPath.

xsl:copy 的一个非常常见的用法可以在 身份转换 中找到:

A very common use of xsl:copy can be found in the identity transformation:

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

注意这里的节点本身是通过xsl:copy复制的 然后通过 xsl:apply-templates 转换子节点,让其他模板有机会干预转换.

Notice that here the node itself is copied via xsl:copy and the children nodes are then transformed via xsl:apply-templates, giving other templates a chance to intervene in the transformation.

  • xsl:copy-of 指令在其必需 @select 属性中评估 XPath,并递归复制所选节点及其子节点.
  • 这是一个深拷贝.
  • xsl:copy-of 指令必须有一个 @select XPath.
  • The xsl:copy-of instruction evaluates the XPath in its required @select attribute and copies the selected nodes and their children nodes, recursively.
  • This is a deep copy.
  • The xsl:copy-of instruction must have a @select XPath.

请注意xsl:copy-of 本来可以用于身份转换,但是在递归过程中允许其他模板有机会匹配所提供的灵活性将会丧失.

Notice that xsl:copy-of could have been used in the identity transformation, however the flexibility afforded by allowing other templates the chance to match during the recursion would have been lost.

这篇关于xsl:copy 和 xsl:copy-of 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆