ล่าสุดการพัฒนาเว็บบทเรียน
 

XSLT <xsl:if> Element


<xsl:if> องค์ประกอบที่จะใช้ในการวางเงื่อนไขการทดสอบกับเนื้อหาของไฟล์ XML ที่


<xsl:if> ธาตุ

ที่จะนำเงื่อนไขถ้าการทดสอบกับเนื้อหาของไฟล์ XML ที่เพิ่ม <xsl:if> องค์ประกอบเอกสาร XSL

วากยสัมพันธ์

<xsl:if test=" สถานที่ที่จะใส่ <xsl:if> ธาตุ

ในการเพิ่มการทดสอบเงื่อนไขเพิ่ม <xsl:if> องค์ประกอบภายใน <xsl:for-each> องค์ประกอบในแฟ้ม 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>My CD Collection</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th>Title</th>
      <th>Artist</th>
      <th>Price</th>
    </tr>
    <xsl:for-each select="catalog/cd">
      <xsl:if test="price &gt; 10">
        <tr>
          <td><xsl:value-of select="title"/></td>
          <td><xsl:value-of select="artist"/></td>
          <td><xsl:value-of select="price"/></td>
        </tr>
      </xsl:if>
    </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>
ลองตัวเอง»

Note: ค่าของที่จำเป็น test แอตทริบิวต์มีการแสดงออกที่จะได้รับการประเมิน

รหัสข้างต้นจะออกเพียงชื่อและศิลปินองค์ประกอบของแผ่นซีดีที่มีราคาที่สูงกว่า 10