English 中文(简体)
XSLT - <if>
  • 时间:2024-11-05

XSLT <if>


Previous Page Next Page  

斜体:f> 标签具体规定了对 no含量的有条件测试。

Declaration

以下是<xsl:if>。 内容。

<xsl:if 
  test = boolean-expression > 
</xsl:if> 

Attributes

Sr.No Name & Description
1

xml数据中的测试条件。

Elements

Number of Occurrences Unpmited

xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:process-instruction, xsl:variable, xsl: when, xsl:with-param, content

xsl:apply-templates, xsl:attribute, xsl:quest-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:process-instruction, xsl:text, xsl: Value-of, xsl:variable,输出要素

Demo Example

这个例子创建了一个“与”;“student>”表;其属性如下:rollno及其子女与lt;firstname> 和lt;lastname> 和lt;nickname>and <marks> by iterating over each students。 它检查的评分超过90,然后印刷学生的详细情况。

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"> 
					
                  <xsl:if test = "marks > 90"> 
                     <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:if> 
               </xsl:for-each> 
					
            </table> 
         </body> 
      </html> 
   </xsl:template>  
</xsl:stylesheet>

Output

Formatted IF Output Advertisements