XSLT <for-each>
Thẻ <xsl: for-each> áp dụng một mẫu lặp đi lặp lại cho mỗi nút.
Tờ khai
Sau đây là khai báo cú pháp của <xsl:for-each> thành phần
<xsl:for-each
   select = Expression >  
</xsl:for-each>Thuộc tính
| Sr.No | Tên & Mô tả | 
|---|---|
| 1 | Select Biểu thức XPath sẽ được đánh giá trong ngữ cảnh hiện tại để xác định tập hợp các nút được lặp lại. | 
Thành phần
| Số lần xuất hiện | Vô hạn | 
|---|---|
| Parent elements | xsl: thuộc tính, xsl: bình luận, xsl: sao chép, xsl: phần tử, xsl: dự phòng, xsl: foreach, xsl: if, xsl: message, xsl: else, xsl: param, xsl: processinginstruction, xsl: template, xsl: biến, xsl: when, xsl: with-param, các phần tử đầu ra. | 
| 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: processing-command, xsl: sort, xsl: text, xsl: value-of, xsl: variable. | 
Ví dụ demo
Ví dụ này tạo một bảng gồm phần tử <student> với thuộc tính rollno của nó và con của nó là <firstname>,<lastname> <nickname> và <marks> bằng cách lặp qua từng học sinh.
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.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
