[技术学习]一直没理解XSLT标准中的Copying一节

http://www.w3.org/TR/xslt#copying

7.5 Copying

<!-- Category: instruction -->
<xsl:copy
use-attribute-sets =qnames>
<!-- Content:template-->
</xsl:copy>

Thexsl:copyelement provides an easy way of copying the current node. Instantiating thexsl:copyelement creates a copy of the current node. The namespace nodes of the current node are automatically copied as well, but the attributes and children of the node are not automatically copied. The content of thexsl:copyelement is a template for the attributes and children of the created node; the content is instantiated only for nodes of types that can have attributes or children (i.e. root nodes and element nodes).

Thexsl:copyelement may have ause-attribute-setsattribute (see[7.1.4 Named Attribute Sets]). This is used only when copying element nodes.

The root node is treated specially because the root node of the result tree is created implicitly. When the current node is the root node,xsl:copywill not create a root node, but will just use the content template.

For example, the identity transformation can be written usingxsl:copyas follows:

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>  <!-- 这里是把apply-templates的内容嵌入中当前拷贝的结点之内 -->
  </xsl:copy>
</xsl:template>

When the current node is an attribute, then if it would be an error to usexsl:attributeto create an attribute with the same name as the current node, then it is also an error to usexsl:copy(see[7.1.3 Creating Attributes withxsl:attribute]).

The following example shows howxml:langattributes can be easily copied through from source to result. If a stylesheet defines the following named template:

<xsl:template name="apply-templates-copy-lang">
 <xsl:for-each select="@xml:lang">
   <xsl:copy/>
 </xsl:for-each>
 <xsl:apply-templates/>
</xsl:template>

then it can simply do

<xsl:call-template name="apply-templates-copy-lang"/>

instead of

<xsl:apply-templates/>

when it wants to copy thexml:langattribute.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值