XSLT <template>
<xsl: template> xác định cách sử dụng lại các mẫu để tạo đầu ra mong muốn cho các nút của một loại / ngữ cảnh cụ thể.
Tờ khai
Sau đây là khai báo cú pháp của <xsl:template> thành phần.
<xsl:template 
   name = Qname 
   match = Pattern 
   priority = number 
   mode = QName >
</xsl:template>Thuộc tính
| Sr.No | Tên & Mô tả | 
|---|---|
| 1 | name Tên của phần tử mà mẫu sẽ được áp dụng. | 
| 2 | match Mẫu biểu thị (các) phần tử mà mẫu sẽ được áp dụng. | 
| 3 | priority Số ưu tiên của một mẫu. Mẫu đối sánh có mức độ ưu tiên thấp không được xem xét từ phía trước mẫu có mức độ ưu tiên cao. | 
| 4 | mode Cho phép phần tử được xử lý nhiều lần để tạo ra một kết quả khác nhau mỗi lần. | 
Thành phần
| Số lần xuất hiện | Vô hạn | 
|---|---|
| Parent elements | xsl: bảng định kiểu, xsl: biến đổi | 
| Child elements | xsl: áp dụng-nhập khẩu, xsl: áp dụng-mẫu, xsl: thuộc tính, xsl: cuộc gọi-mẫu, xsl: chọn, xsl: nhận xét, xsl: sao chép, xsl: sao chép, xsl: phần tử, xsl: dự phòng, xsl: for-each, xsl: if, xsl: message, xsl: number, xsl: param, xsl: processing-tutorial, xsl: text, xsl: value-of, xsl: variable, output element | 
Ví dụ demo
Quy tắc mẫu này có một mẫu xác định các phần tử <student> và tạo đầu ra ở định dạng bảng.
students.xml
<?xml version = "1.0"?> 
<?xml-stylesheet type = "text/xsl" href = "students.xsl"?> 
<class> 
   <student rollno = "393"> 
      <firstname>Dinkar</firstname> 
      <lastname>Kad</lastname> 
      <nickname>Dinkar</nickname> 
      <marks>85</marks> 
   </student> 
   <student rollno = "493"> 
      <firstname>Vaneet</firstname> 
      <lastname>Gupta</lastname> 
      <nickname>Vinni</nickname> 
      <marks>95</marks> 
   </student> 
   <student rollno = "593"> 
      <firstname>Jasvir</firstname> 
      <lastname>Singh</lastname> 
      <nickname>Jazz</nickname> 
      <marks>90</marks> 
   </student> 
</class>students_imports.xsl
<?xml version = "1.0" encoding = "UTF-8"?> 
<xsl:stylesheet version = "1.0" 
   xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">  
	
   <xsl:template match = "/"> 
      <html> 
         <body> 
            <h2>Students</h2> 
            <table border = "1"> 
               <tr bgcolor = "#9acd32"> 
                  <th>Roll No</th> 
                  <th>First Name</th> 
                  <th>Last Name</th> 
                  <th>Nick Name</th> 
                  <th>Marks</th> 
               </tr>
					
               <xsl:for-each select = "class/student"> 
                  <tr> 
                     <td><xsl:value-of select = "@rollno"/></td> 
                     <td><xsl:value-of select = "firstname"/></td> 
                     <td><xsl:value-of select = "lastname"/></td> 
                     <td><xsl:value-of select = "nickname"/></td> 
                     <td><xsl:value-of select = "marks"/></td>
                  </tr> 
               </xsl:for-each> 
            </table> 
         </body> 
      </html> 
   </xsl:template>  
</xsl:stylesheet>Đầu ra
