Element <xsl:apply-imports> in XSLT
Defining and using
Element <xsl:apply-imports> can apply template rules from imported style sheets.
Priorities of template rules imported from style sheets are lower than those in the main style sheet. If you want to use a specific template rule from the imported style sheet instead of an equivalent rule in the main style sheet, you will use the <xsl:apply-imports> element.
Ngữ pháp
<xsl:apply-imports/>
Thuộc tính
None
Mô hình
Giả sử chúng ta có một biểu mẫu tên là "standard.xsl", trong đó chứa các quy tắc mẫu cho phần tử message:
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="message"> <h2><xsl:apply-templates/></h2> </xsl:template> </xsl:stylesheet>
Một biểu mẫu phong cách khác có thể nhập "standard.xsl" và chỉnh sửa message, giống như vậy:
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:import href="standard.xsl"/> <xsl:template match="message"> <div style="border:solid blue"> <xsl:apply-imports/> </div> </xsl:template> </xsl:stylesheet>
Kết quả là: sẽ chuyển một thông điệp thành các phần tử lưới:
<div style="border:solid blue"><h2>...</h2></div>