Phần tử <xsl:copy-of> trong XSLT
Định nghĩa và cách sử dụng
<xsl:copy-of> phần tử có thể tạo bản sao của phần tử hiện tại.
Ghi chú:Namespace của phần tử hiện tại, các phần tử con và thuộc tính sẽ được sao chép tự động!
Lưu ý:Các phần tử này có thể được sử dụng để chèn nhiều bản sao của cùng một phần tử vào các vị trí khác nhau trong đầu ra.
Ngữ 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>Điều kiệ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>