XSLT <xsl:if> 요소
- 이전 페이지 XSLT <xsl:sort>
- 다음 페이지 XSLT <choose>
<xsl:if> 요소는 XML 파일 내용에 대한 조건 검사를 배치하는 데 사용됩니다。
<xsl:if> 요소
XML 파일 내용에 대한 조건 검사를 추가하려면, XSL 문서에 <xsl:if> 요소를 추가하세요。
문법
<xsl:if test="expression"> ... ... 조건이 성립되면 출력... ... </xsl:if>
<xsl:if> 요소를 어디에 배치하죠
추가적인 조건 검사를 추가하려면, XSL 파일에서 <xsl:for-each> 요소 내에 <xsl:if> 요소를 추가하세요:
<?xml version="1.0" encoding="ISO-8859-1"?> <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> </tr> <xsl:for-each select="catalog/cd"><xsl:if test="price > 10">
<tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr></xsl:if>
</xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
주의사항:필수 test 속성의 값에는 계산할 필요가 있는 표현식이 포함됩니다.
위의 코드는 가격이 10보다 높은 CD의 title 및 artist 요소만 출력합니다.
위의 변환 결과는 이렇게 보입니다:

- 이전 페이지 XSLT <xsl:sort>
- 다음 페이지 XSLT <choose>