<xsl:copy> 元素

将当前节点从源复制到输出。

<xsl:copy
  use-attribute-sets = QNames
</xsl:copy>

特性

  • use-attribute-sets
    空白分隔的属性集列表,按照限定名 列表的指定。指定此属性将在每个列出的属性集中声明每个属性。

元素信息

出现次数

无限制

父元素

xsl:attributexsl:comment、xsl:copy、xsl:elementxsl:fallbackxsl:for-eachxsl:ifxsl:messagexsl:otherwisexsl:paramxsl:processing-instructionxsl:templatexsl:variablexsl:whenxsl:with-param、输出元素

子元素

xsl:apply-templatesxsl:attributexsl:call-templatexsl:choosexsl:comment、xsl:copy、xsl:copy-ofxsl:elementxsl:for-eachxsl:ifxsl:processing-instructionxsl:textxsl:value-ofxsl:variable、输出元素

注释

<xsl:copy> 元素在输出中创建一个与当前节点的名称、命名空间和类型相同的节点。属性和子元素不会自动复制。通过此元素可以转换标识。

示例

以下示例对整个文档执行标识转换。标识转换将源中的每个节点复制到输出以提供逻辑等效树。它不生成字符对字符的等效:实体将被扩展,且未标记为重要的空白可能被删除。

XML 文件 (booksshort.xml)

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="identityxfm.xsl"?>
<catalog>
    <book id="bk101">
        <author>Gambardella, Matthew</author>
        <title>XML Developer's Guide</title>
        <genre>Computer</genre>
        <price>44.95</price>
        <publish_date>2000-10-01</publish_date>        
        <description>An in-depth look at creating applications with
 XML.</description>
    </book>
    <book id="bk102">
        <author>Ralls, Kim</author>
        <title>Midnight Rain</title>
        <genre>Fantasy</genre>
        <price>5.95</price>
        <publish_date>2000-12-16</publish_date>
        <description>A former architect battles corporate zombies,
 an evil sorceress, and her own childhood to become queen of the
 world.</description>
    </book>
    <book id="bk103">
        <author>Corets, Eva</author>
        <title>Maeve Ascendant</title>
        <genre>Fantasy</genre>
        <price>5.95</price>
        <publish_date>2000-11-17</publish_date>
        <description>After the collapse of a nanotechnology society
 in England, the young survivors lay the foundation for a new 
society.</description>
    </book>
</catalog>

XSLT 文件 (identityxfm.xsl)

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

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

</xsl:stylesheet>

输出

此为格式输出的一部分,在右边截断:

Gambardella, MatthewComputer44.952000-10-01An in-depth look and her own childhood to become queen of the world.Corets, EvaFa

以下是处理器输出:

<?xml version="1.0"?><?xml-stylesheet type="text/xsl"

href="identityxfm.xsl"?><catalog><book id="bk101"><author>Gambardella,

Matthew</author><title>XML Developer's

Guide</title><genre>Computer</genre><price>44.95</price><publish_date>2000

-10-01</publish_date><description>An in-depth look at creating

applications with

XML.</description></book><book id="bk102">

...

</book></catalog>