Đлемент <xsl:copy-of> trong XSLT

Định nghĩa và cách sử dụng

<xsl:copy-of> Đлемент có thể tạo bản sao của nút hiện tại.

Ghi chú:Namespace của nút hiện tại, các nút con và thuộc tính sẽ được sao chép tự động!

Lưu ý:Đлемент này có thể được sử dụng để chèn nhiều bản sao của các nút tương tự vào các vị trí khác nhau trong đầu ra.

Cú pháp

<xsl:copy-of select="expression"/>

Thuộc tính

Thuộc tính Giá trị Mô tả
select expression Bắt buộc. Định nghĩa nội dung cần sao chép.

Mô hình

Ví dụ 1

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="header">
  <tr>
  <th>Thành phần</th>
  <th>Mô tả</th>
  </tr>
</xsl:variable>
<xsl:template match="/">
  <html>
  <body>
  <table>
    <xsl:copy-of select="$header" />
    <xsl:for-each select="reference/record">
    <tr>
    <xsl:if test="category='XML'">
      <td><xsl:value-of select="element"/></td>
      <td><xsl:value-of select="description"/></td>
    </xsl:if>
    </tr>
    </xsl:for-each>
  </table>
  <br />
  <table>
    <xsl:copy-of select="$header" />
    <xsl:for-each select="table/record">
    <tr>
    <xsl:if test="category='XSL'">
      <td><xsl:value-of select="element"/></td>
      <td><xsl:value-of select="description"/></td>
    </xsl:if>
    </tr>
    </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>