<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="/">
- <HTML>
- <HEAD>
- <TITLE>導遊</TITLE>
- <STYLE TYPE="text/css">
- H2 {TEXT-ALIGN:CENTER;}
- .greenBackground {BACKGROUND-COLOR:LIGHTGREEN; TEXT-ALIGN:CENTER;}
- .yellowBackground {BACKGROUND-COLOR:YELLOW; TEXT-ALIGN:CENTER; FONT-WEIGHT:BOLD; FONT-SIZE:14pt;}
- .salmonBackground {BACKGROUND-COLOR:LIGHTSALMON; TEXT-ALIGN:CENTER; FONT-SIZE:12pt;}
- </STYLE>
- </HEAD>
- <BODY>
- <H2>頂級旅遊目的地</H2>
- <xsl:apply-templates select="tourGuide"/>
- </BODY>
- </HTML>
</xsl:template> <xsl:template match="tourGuide">
- <TABLE BORDER="1" WIDTH="100%">
- <xsl:for-each select="city/country">
- <xsl:sort select="countryName"/>
- <xsl:if test="population > 10000">
- <TR>
- <TD CLASS="greenBackground"><BR/>
- <xsl:text>國家: </xsl:text><xsl:value-of select="countryName"/></TD><BR/>
- <TD CLASS="greenBackground"><BR/>
- <xsl:text>人口: </xsl:text><xsl:value-of select="population"/>
- </TD>
- <xsl:for-each select="topDestination">
- <TD CLASS="yellowBackground"><BR/>
- <xsl:text>頂級目的地: </xsl:text><xsl:value-of select="destinationName"/>
- </TD>
- </xsl:for-each>
- <xsl:for-each select="destination">
- <TD CLASS="yellowBackground"><BR/>
- <xsl:text>目的地: </xsl:text><xsl:value-of select="destinationName"/>
- </TD>
- </xsl:for-each>
- </TR>
- </xsl:if>
- </xsl:for-each>
- </TABLE>
- </xsl:template>
</xsl:stylesheet>
|
表 4-3: 一對一關係的 XML 樣式表 - country_dest.xsl
表 4-3 中的 XML 樣式表介紹了 if 語句以及排序元素的能力。
if 語句根據 "test" 屬性中給定的條件的評估執行程式碼,例如:
<xsl:if test="population >= 10000">
- 大城鎮
</xsl:if>
<xsl:if test="population < 10000">
- 小鎮
</xsl:if>
條件可能的表示式為
運算子 |
含義 |
| = | == |
| != | 兩個值的相等 |
| != | 兩個值的不想等 |
| < | 小於 |
| > | 大於 |
| <= | 小於或等於 |
| >= | 大於或等於 |
| and | 邏輯與連線 |
or