Condividi tramite


Elemento <xsl:copy>

Copia il nodo corrente dall'origine all'output.

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

Attributi

  • use-attribute-sets
    Un elenco di insiemi di attributi separati da spazi vuoti, specificato come un elenco di Nomi completi (XSLT). Se si specifica questo attributo, viene dichiarato ogni attributo in ogni set di attributi elencati.

Informazioni sull'elemento

Numero di occorrenze

Illimitato

Elementi padre

xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, elementi di output

Elementi figlio

xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:text, xsl:value-of, xsl:variable, elementi di output

Note

L'elemento <xsl:copy> crea, nell'output, un nodo in cui il nome, lo spazio dei nomi e il tipo coincidono con quelli del nodo corrente. Gli attributi e gli elementi figlio non vengono copiati automaticamente. Questo elemento consente la trasformazione di identità.

Esempio

Nell'esempio seguente viene eseguita una trasformazione di identità in un intero documento. Nella trasformazione di identità viene copiato nell'output ciascun nodo dell'origine per fornire una struttura logicamente equivalente. Non viene prodotta un'equivalenza carattere per carattere: le entità verranno espanse e gli spazi vuoti non contrassegnati come significativi verranno rimossi.

File 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>

File 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>

Output

Di seguito è riportata una parte dell'output formattato, trancato a destra:

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

L'output del processore è il seguente:

<?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>