Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

XML - Managing Data Exchange/C.4

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

XML Style Sheet <TABLE border="1" cellspacing="0" cellpadding="2"> <TR><TD bgcolor="lightyellow"><?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="/"> Tour Guide 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;} <H2>Top Tourist Destinations</H2> <xsl:apply-templates select="tourGuide"/> </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 &gt; 10000"> <TR> <TD CLASS="greenBackground"><BR/> <xsl:text>Country: </xsl:text><xsl:value-of select="countryName"/></TD><BR/> <TD CLASS="greenBackground"><BR/> <xsl:text>Population: </xsl:text><xsl:value-of select="population"/> </TD> <xsl:for-each select="topDestination"> <TD CLASS="yellowBackground"><BR/> <xsl:text>Top Destination: </xsl:text><xsl:value-of select="destinationName"/> </TD> </xsl:for-each> <xsl:for-each select="destination"> <TD CLASS="yellowBackground"><BR/> <xsl:text>Destination: </xsl:text><xsl:value-of select="destinationName"/> </TD> </xsl:for-each> </TR> </xsl:if> </xsl:for-each> </TABLE> </xsl:template> </xsl:stylesheet> </td></tr></table> Table 4-3: XML style sheet for a one-to-one relationship – country_dest.xsl The XML style sheet in Table 4-3 introduces the if statement as well as the ability to sort elements. The if statement executes code based on the evaluation of the condition given in the "test" attribute,e.g. <xsl:if test="population &gt;= 10000"> Big Town </xsl:if> <xsl:if test="population &lt; 10000"> Small Town </xsl:if> Possible expressions for the condition are Operator Meaning =equality of two values !=inequality of two values &lt;less than &gt;greater than &lt;=less than or equal &gt;=greater than or equal andlogical and-conjunction orlogical or-conjunction Output can be sorted based on the value of the select attribute of the <xsl:sort> element.