Yếu tố <xsl:include> của XSLT
Định nghĩa và cách sử dụng
<xsl:include> là yếu tố cấp cao (top-level element), bao gồm nội dung của một tệp樣 thức vào một tệp樣 thức khác.
Chú ý:Tệp樣 thức được bao gồm (included style sheet) có cùng mức độ ưu tiên với tệp樣 thức bao gồm (including style sheet).
Chú ý:Các yếu tố này phải là con của <xsl:stylesheet> hoặc <xsl:transform>.
Ngữ pháp
<xsl:include href="URI"/>
Thuộc tính
Thuộc tính | Giá trị | Mô tả |
---|---|---|
href | URI | Bắt buộc. Định nghĩa URI của tệp樣 thức cần bao gồm. |
Thực hành
Ví dụ 1
Dưới đây là ví dụ bao gồm tệp樣 thức có tên là xslincludefile.xsl:
<?xml version=1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" omit-xml-declaration="yes"/> <xsl:template match="/"> <xsl:for-each select="COLLECTION/BOOK"> <xsl:apply-templates select="TITLE"/> <xsl:apply-templates select="AUTHOR"/> <xsl:apply-templates select="PUBLISHER"/> <BR/> <!-- add this --> </xsl:for-each> </xsl:template> <xsl:template match="TITLE"> <DIV STTLE="color:blue"> Tiêu đề: <xsl:value-of select="."/> </DIV> </xsl:template> <xsl:include href="/xsl/xslincludefile.xsl" /> </xsl:stylesheet>