1 <?xml version="1.0"?> 2 <!-- 3 An experimental Qt Designer form conversion stylesheet. 4 5 Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk> 6 7 This library is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Lesser General Public 9 License as published by the Free Software Foundation; either 10 version 2.1 of the License, or (at your option) any later version. 11 12 This library is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Lesser General Public License for more details. 16 17 You should have received a copy of the GNU Lesser General Public 18 License along with this library; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 --> 21 <xsl:stylesheet version="1.0" 22 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 23 xmlns:set="http://exslt.org/sets" 24 xmlns:math="http://exslt.org/math" 25 xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> 26 27 <xsl:output indent="yes"/> 28 29 30 31 <!-- Start at the top, producing a template file. --> 32 33 <xsl:template match="UI"> 34 <html xmlns="http://www.w3.org/1999/xhtml"> 35 <head> 36 <title><xsl:value-of select="widget/property[@name='caption']/string/text()"/></title> 37 <link xmlns:xlink="http://www.w3.org/1999/xlink" href="styles/styles.css" rel="stylesheet" type="text/css" /> 38 <script type="text/javascript" src="scripts/sarissa.js"> </script> 39 <script type="text/javascript" src="scripts/XSLForms.js"> </script> 40 </head> 41 <body> 42 <xsl:apply-templates select="widget"/> 43 </body> 44 </html> 45 </xsl:template> 46 47 48 49 <!-- Reproduce the layout. --> 50 51 <xsl:template match="grid"> 52 <xsl:variable name="grid" select="."/> 53 <table xmlns="http://www.w3.org/1999/xhtml"> 54 <!-- Get the row numbers in ascending order. --> 55 <xsl:for-each select="set:distinct($grid/*/@row)"> 56 <xsl:sort select="." data-type="number" order="ascending"/> 57 <xsl:variable name="row" select="."/> 58 <tr> 59 <!-- Get all elements in the row, ordered by column number. --> 60 <xsl:call-template name="grid-column"> 61 <xsl:with-param name="column" select="math:min($grid/*[@row=$row]/@column)"/> 62 <xsl:with-param name="row" select="$row"/> 63 <xsl:with-param name="grid" select="$grid"/> 64 <xsl:with-param name="last-column">-1</xsl:with-param> 65 </xsl:call-template> 66 </tr> 67 </xsl:for-each> 68 </table> 69 </xsl:template> 70 71 <xsl:template name="grid-column"> 72 <xsl:param name="column"/> 73 <xsl:param name="row"/> 74 <xsl:param name="grid"/> 75 <xsl:param name="last-column"/> 76 <xsl:param name="last-colspan">1</xsl:param> 77 <!-- Insert missing cells. --> 78 <!-- NOTE: This does not handle rowspan usage. --> 79 <xsl:if test="$column != $last-column + $last-colspan"> 80 <xsl:variable name="spanned-columns" select="$grid/*[$row > @row and @row + @rowspan > $row and @column > $last-column and $column > @column]/@column"/> 81 <xsl:choose> 82 <xsl:when test="count($spanned-columns) != 0"> 83 <xsl:variable name="last-spanned-column" select="math:highest($spanned-columns)"/> 84 <xsl:variable name="last-spanned-colspan" select="$last-spanned-column/../@colspan"/> 85 <xsl:if test="$column != $last-spanned-column + $last-spanned-colspan"> 86 <td colspan="{$column - $last-spanned-column - $last-spanned-colspan}" xmlns="http://www.w3.org/1999/xhtml"> 87 </td> 88 </xsl:if> 89 </xsl:when> 90 <xsl:otherwise> 91 <td colspan="{$column - $last-column - $last-colspan}" xmlns="http://www.w3.org/1999/xhtml"> 92 </td> 93 </xsl:otherwise> 94 </xsl:choose> 95 </xsl:if> 96 <!-- Remember useful information. --> 97 <xsl:variable name="this-column" select="$grid/*[@row=$row and @column=$column]"/> 98 <xsl:variable name="this-colspan" select="$this-column/@colspan"/> 99 <!-- Insert this cell. --> 100 <td xmlns="http://www.w3.org/1999/xhtml"> 101 <!-- Add colspan and rowspan details. --> 102 <xsl:apply-templates select="$this-colspan|$this-column/@rowspan"/> 103 <!-- Transform the element. --> 104 <xsl:apply-templates select="$this-column"/> 105 </td> 106 <!-- Find remaining cells in this row. --> 107 <xsl:if test="count($grid/*[@row=$row and @column > $column]) > 0"> 108 <xsl:choose> 109 <xsl:when test="$this-colspan"> 110 <xsl:call-template name="grid-column"> 111 <xsl:with-param name="column" select="math:min($grid/*[@row=$row and @column > $column]/@column)"/> 112 <xsl:with-param name="row" select="$row"/> 113 <xsl:with-param name="grid" select="$grid"/> 114 <xsl:with-param name="last-column" select="$column"/> 115 <xsl:with-param name="last-colspan" select="$this-colspan"/> 116 </xsl:call-template> 117 </xsl:when> 118 <xsl:otherwise> 119 <xsl:call-template name="grid-column"> 120 <xsl:with-param name="column" select="math:min($grid/*[@row=$row and @column > $column]/@column)"/> 121 <xsl:with-param name="row" select="$row"/> 122 <xsl:with-param name="grid" select="$grid"/> 123 <xsl:with-param name="last-column" select="$column"/> 124 </xsl:call-template> 125 </xsl:otherwise> 126 </xsl:choose> 127 </xsl:if> 128 </xsl:template> 129 130 <xsl:template match="spacer"> 131 </xsl:template> 132 133 <xsl:template match="vbox"> 134 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 135 </xsl:template> 136 137 <xsl:template match="widget"> 138 <xsl:apply-templates select="property[@name='geometry']"/> 139 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 140 </xsl:template> 141 142 143 144 <!-- Specific widgets. --> 145 146 <xsl:template match="widget[@class='QComboBox']"> 147 <select xmlns="http://www.w3.org/1999/xhtml"> 148 <xsl:variable name="name-prop" select="property[@name='name']"/> 149 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 150 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 151 <xsl:apply-templates select="item"/> 152 </select> 153 </xsl:template> 154 155 <xsl:template match="widget[@class='QListBox']"> 156 <select xmlns="http://www.w3.org/1999/xhtml" multiple="multiple"> 157 <xsl:variable name="name-prop" select="property[@name='name']"/> 158 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 159 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 160 <xsl:apply-templates select="item"/> 161 </select> 162 </xsl:template> 163 164 <xsl:template match="item"> 165 <option xmlns="http://www.w3.org/1999/xhtml"> 166 <xsl:variable name="value-prop" select="property[@name='text']"/> 167 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 168 <xsl:value-of select="$value-prop/string/text()"/> 169 </option> 170 </xsl:template> 171 172 <xsl:template match="widget[@class='QLabel']"> 173 <xsl:variable name="value-prop" select="property[@name='text']"/> 174 <!-- NOTE: Permitting element generation from the text. --> 175 <xsl:value-of disable-output-escaping="yes" select="$value-prop/string/text()"/> 176 </xsl:template> 177 178 <xsl:template match="widget[@class='QPushButton']"> 179 <input xmlns="http://www.w3.org/1999/xhtml" type="submit"> 180 <xsl:variable name="name-prop" select="property[@name='name']"/> 181 <xsl:variable name="value-prop" select="property[@name='text']"/> 182 <xsl:attribute name="template:attribute-button"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 183 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 184 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 185 </input> 186 </xsl:template> 187 188 <xsl:template match="widget[@class='QLineEdit']"> 189 <input xmlns="http://www.w3.org/1999/xhtml" type="text"> 190 <xsl:variable name="name-prop" select="property[@name='name']"/> 191 <xsl:variable name="value-prop" select="property[@name='text']"/> 192 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 193 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 194 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 195 </input> 196 </xsl:template> 197 198 <xsl:template match="widget[@class='QTextEdit']"> 199 <textarea xmlns="http://www.w3.org/1999/xhtml"> 200 <xsl:variable name="name-prop" select="property[@name='name']"/> 201 <xsl:variable name="value-prop" select="property[@name='text']"/> 202 <xsl:attribute name="template:attribute-area"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 203 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 204 <xsl:value-of select="$value-prop/string/text()"/> 205 </textarea> 206 </xsl:template> 207 208 <xsl:template match="widget[@class='QRadioButton']"> 209 <input xmlns="http://www.w3.org/1999/xhtml" type="radio"> 210 <xsl:variable name="name-prop" select="property[@name='name']"/> 211 <xsl:variable name="value-prop" select="property[@name='text']"/> 212 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 213 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 214 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 215 </input> 216 </xsl:template> 217 218 219 220 <!-- Geometry. --> 221 222 <xsl:template match="property[@name='geometry']"> 223 <xsl:apply-templates select="rect/*[1]"> 224 <xsl:with-param name="style">position: absolute</xsl:with-param> 225 </xsl:apply-templates> 226 </xsl:template> 227 228 <xsl:template name="make-geometry"> 229 <xsl:param name="style"/> 230 <xsl:variable name="dimension" select="following-sibling::*[1]"/> 231 <xsl:choose> 232 <xsl:when test="not($dimension)"> 233 <xsl:attribute name="style"><xsl:value-of select="$style"/></xsl:attribute> 234 </xsl:when> 235 <xsl:otherwise> 236 <xsl:apply-templates select="$dimension"> 237 <xsl:with-param name="style" select="$style"/> 238 </xsl:apply-templates> 239 </xsl:otherwise> 240 </xsl:choose> 241 </xsl:template> 242 243 <xsl:template match="x"> 244 <xsl:param name="style"/> 245 <xsl:call-template name="make-geometry"> 246 <xsl:with-param name="style"><xsl:value-of select="$style"/>; left: <xsl:value-of select="text()"/>px</xsl:with-param> 247 </xsl:call-template> 248 </xsl:template> 249 250 <xsl:template match="y"> 251 <xsl:param name="style"/> 252 <xsl:call-template name="make-geometry"> 253 <xsl:with-param name="style"><xsl:value-of select="$style"/>; top: <xsl:value-of select="text()"/>px</xsl:with-param> 254 </xsl:call-template> 255 </xsl:template> 256 257 <xsl:template match="width"> 258 <xsl:param name="style"/> 259 <xsl:call-template name="make-geometry"> 260 <xsl:with-param name="style"><xsl:value-of select="$style"/>; width: <xsl:value-of select="text()"/>px</xsl:with-param> 261 </xsl:call-template> 262 </xsl:template> 263 264 <xsl:template match="height"> 265 <xsl:param name="style"/> 266 <xsl:call-template name="make-geometry"> 267 <xsl:with-param name="style"><xsl:value-of select="$style"/>; height: <xsl:value-of select="text()"/>px</xsl:with-param> 268 </xsl:call-template> 269 </xsl:template> 270 271 272 273 <!-- Identification. --> 274 275 <xsl:template match="property[@name='name']"> 276 </xsl:template> 277 278 279 280 <!-- Labels and values. --> 281 282 <xsl:template match="property[@name='text']"> 283 </xsl:template> 284 285 286 287 <!-- Captions. --> 288 289 <xsl:template match="property[@name='caption']"> 290 </xsl:template> 291 292 293 294 <!-- Copy attributes. --> 295 296 <xsl:template match="@*"> 297 <xsl:copy> 298 <xsl:apply-templates select="node()"/> 299 </xsl:copy> 300 </xsl:template> 301 302 </xsl:stylesheet>