Язык преобразований XSL


D.2 Пример данных - часть 2


Полученный HTML документ:

<html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Sales Results By Division</title> </head> <body> <table border="1"> <tr> <th>Division</th><th>Revenue</th><th>Growth</th><th>Bonus</th> </tr> <tr> <td><em>North</em></td><td>10</td><td>9</td><td>7</td> </tr> <tr> <td><em>West</em></td><td>6</td><td style="color:red">-1.5</td><td>2</td> </tr> <tr> <td><em>South</em></td><td>4</td><td>3</td><td>4</td> </tr> </table> </body> </html>

Следующий стиль преобразует данные в SVG:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd">

<xsl:output method="xml" indent="yes" media-type="image/svg"/>

<xsl:template match="/">

<svg width = "3in" height="3in"> <g style = "stroke: #000000"> <!-- draw the axes --> <line x1="0" x2="150" y1="150" y2="150"/> <line x1="0" x2="0" y1="0" y2="150"/> <text x="0" y="10">Revenue</text> <text x="150" y="165">Division</text> <xsl:for-each select="sales/division"> <!-- define some useful variables -->

<!-- the bar's x position --> <xsl:variable name="pos" select="(position()*40)-30"/>

<!-- the bar's height --> <xsl:variable name="height" select="revenue*10"/>




- Начало -  - Назад -  - Вперед -