XSLT <xsl: copy-of>
❮ Toàn bộ tham chiếu phần tử XSLT
Định nghĩa và Cách sử dụng
Phần tử <xsl: copy-of> tạo một bản sao của nút hiện tại.
Lưu ý: Các nút không gian tên, nút con và thuộc tính của nút hiện tại cũng được sao chép tự động!
Mẹo: Phần tử này có thể được sử dụng để chèn nhiều bản sao của cùng một nú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
Attribute | Value | Description |
---|---|---|
select | expression | Required. Specifies what to be copied |
ví dụ 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>
❮ Toàn bộ tham chiếu phần tử XSLT