Share via


<xsl:copy> 要素

現在のノードをソースから出力にコピーします。

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

属性

  • use-attribute-sets
    修飾名 (XSLT) のリストとして指定された、空白で区切られた属性セットのリスト。 この属性を指定することで、列挙された属性のセット内の各属性を宣言します。

要素情報

出現回数

無制限

親要素

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> 要素は、現在のノードと同じ名前、名前空間、および型を持つノードを作成し、出力に含めます。 属性と子は、自動的にはコピーされません。 この要素を利用すれば、識別情報を変換できます。

使用例

ドキュメント全体に対して識別情報の変換を実行する例を次に示します。 識別情報の変換を実行すると、ソース内の各ノードが出力にコピーされ、論理的に等価なツリーが生成されます。 1 文字 1 文字が等しくなるわけではありません。エンティティは展開され、重要な値として指定されていない空白文字は削除される場合があります。

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>