English 中文(简体)
XSLT - <foreach>
  • 时间:2024-12-22

XSLT <for-each>


Previous Page Next Page  

斜体:每条 no子都多次使用模板。

Declaration

以下是<xsl:for-each>。 要素

<xsl:for-each
   select = Expression >  
</xsl:for-each>

Attributes

Sr.No Name & Description
1

应在目前情况下评估创伤性表达,以确定拟消毒的一组节点。

Elements

Number of Occurrences Unpmited

xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:foreach, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processinstruction, xsl:template, xsl:variable, xsl: when, xsl:with-param,输出要素。

xsl:apply-imports, xsl:apply-templates, xsl:attribute, xsl:quest-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:fallback, xsl:if, xsl:message, xsl: number, xsl: number, xsl:tosl:process-instruction, xsl:sort, xsl:

Demo Example

举例来说,这部表格是:“和”的表;其子号及其子女;第一名称与“;”的表中;最后名称与“;”的表格;“nick”的表;以及“lt”的表;和“mark”的元素;对每个学生进行 it。

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>

Output

Formatted Output Advertisements