Displaying the Final Board


I'll skip the function that computes the knight 's tour for the moment, and describe the relatively easy task of outputting the final result as HTML. Like the rest of the stylesheet, this logic is greatly simplified in XSLT 2.0:

  <xsl:template name="print-board">   <!-- Output the board in HTML format -->   <xsl:param name="board" as="xs:integer*" />   <html>   <head>   <title>Knight's tour</title>   </head>   <body>   <div align="center">   <h1>Knight's tour starting at <xsl:value-of select="$start"/></h1>   <table border="1" cellpadding="4" size="{count($board)}">   <xsl:for-each select="0 to 7">   <xsl:variable name="row" select="."/>   <tr>   <xsl:for-each select="0 to 7">   <xsl:variable name="column" select="."/>   <xsl:variable name="color"   select="if ((($row + $column) mod 2)=1)   then 'xffff44' else 'white'"/>   <td align="center" bgcolor="{$color}">   <xsl:value-of select="$board[$row * 8 + $column + 1]"/>   </td>   </xsl:for-each>   </tr>   </xsl:for-each>   </table>   </div>   </body>   </html>   </xsl:template>  

The template contains a little bit of logic to achieve the traditional checkerboard coloring of the squares, using the «mod » operator to test whether the sum of the row number and the column number is a multiple of 2.

The actual content of each square is the move number, extracted from the relevant item in the sequence representing the board.




XSLT 2.0 Programmer's Reference
NetBeansв„ў IDE Field Guide: Developing Desktop, Web, Enterprise, and Mobile Applications (2nd Edition)
ISBN: 764569090
EAN: 2147483647
Year: 2003
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net