ล่าสุดการพัฒนาเว็บบทเรียน
 

XSLT <xsl:copy-of> Element


<สมบูรณ์ XSLT ธาตุอ้างอิง

ความหมายและการใช้งาน

<xsl:copy-of> องค์ประกอบสร้างสำเนาของโหนดปัจจุบัน

Note: โหนด Namespace โหนดเด็กและแอตทริบิวต์ของโหนดปัจจุบันจะถูกคัดลอกโดยอัตโนมัติเช่นกัน!

Tip: องค์ประกอบนี้สามารถใช้ในการแทรกหลายสำเนาของโหนดเดียวกันเข้าไปในสถานที่ที่แตกต่างกันในการส่งออก


วากยสัมพันธ์

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

แอตทริบิวต์

คุณลักษณะ ความคุ้มค่า ลักษณะ
selectexpression จำเป็นต้องใช้ ระบุสิ่งที่จะถูกคัดลอก

ตัวอย่างที่ 1

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

<xsl:variable name="header">
  <tr>
  <th>Element</th>
  <th>Description</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>

<สมบูรณ์ XSLT ธาตุอ้างอิง