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="hbox"> 138 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 139 </xsl:template> 140 141 <xsl:template match="widget"> 142 <xsl:apply-templates select="property[@name='geometry']"/> 143 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 144 </xsl:template> 145 146 <!-- Container widgets. --> 147 148 <xsl:template match="widget[@class='QFrame']"> 149 <xsl:variable name="name-prop" select="property[@name='name']"/> 150 <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 151 <xsl:apply-templates select="property[@name='geometry']"/> 152 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 153 </xsl:template> 154 155 <xsl:template match="widget[@class='QTabWidget']"> 156 <xsl:variable name="name-prop" select="property[@name='name']"/> 157 <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 158 <xsl:apply-templates select="property[@name='geometry']"/> 159 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 160 </xsl:template> 161 162 <xsl:template match="widget[@class='QWidgetStack']"> 163 <xsl:variable name="name-prop" select="property[@name='name']"/> 164 <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 165 <xsl:apply-templates select="property[@name='geometry']"/> 166 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 167 </xsl:template> 168 169 <xsl:template match="widget[@class='QWidget']"> 170 <xsl:apply-templates select="property[@name='geometry']"/> 171 <xsl:apply-templates select="*[not(local-name() = 'property') and not(local-name() = 'attribute')]"/> 172 </xsl:template> 173 174 <!-- Specific widgets. --> 175 176 <xsl:template match="widget[@class='QComboBox']"> 177 <select xmlns="http://www.w3.org/1999/xhtml"> 178 <xsl:variable name="name-prop" select="property[@name='name']"/> 179 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 180 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 181 <xsl:apply-templates select="item"/> 182 </select> 183 </xsl:template> 184 185 <xsl:template match="widget[@class='QListBox']"> 186 <select xmlns="http://www.w3.org/1999/xhtml" multiple="multiple"> 187 <xsl:variable name="name-prop" select="property[@name='name']"/> 188 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 189 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 190 <xsl:apply-templates select="item"/> 191 </select> 192 </xsl:template> 193 194 <xsl:template match="item"> 195 <option xmlns="http://www.w3.org/1999/xhtml"> 196 <xsl:variable name="value-prop" select="property[@name='text']"/> 197 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 198 <xsl:value-of select="$value-prop/string/text()"/> 199 </option> 200 </xsl:template> 201 202 <xsl:template match="widget[@class='QLabel']"> 203 <xsl:variable name="value-prop" select="property[@name='text']"/> 204 <!-- NOTE: Permitting element generation from the text. --> 205 <xsl:value-of disable-output-escaping="yes" select="$value-prop/string/text()"/> 206 </xsl:template> 207 208 <xsl:template match="widget[@class='QPushButton']"> 209 <input xmlns="http://www.w3.org/1999/xhtml" type="submit"> 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-button"><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 <xsl:template match="widget[@class='QLineEdit']"> 219 <input xmlns="http://www.w3.org/1999/xhtml" type="text"> 220 <xsl:variable name="name-prop" select="property[@name='name']"/> 221 <xsl:variable name="value-prop" select="property[@name='text']"/> 222 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 223 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 224 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 225 </input> 226 </xsl:template> 227 228 <xsl:template match="widget[@class='QTextEdit']"> 229 <textarea xmlns="http://www.w3.org/1999/xhtml"> 230 <xsl:variable name="name-prop" select="property[@name='name']"/> 231 <xsl:variable name="value-prop" select="property[@name='text']"/> 232 <xsl:attribute name="template:attribute-area"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 233 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 234 <xsl:value-of select="$value-prop/string/text()"/> 235 </textarea> 236 </xsl:template> 237 238 <xsl:template match="widget[@class='QRadioButton']"> 239 <input xmlns="http://www.w3.org/1999/xhtml" type="radio"> 240 <xsl:variable name="name-prop" select="property[@name='name']"/> 241 <xsl:variable name="value-prop" select="property[@name='text']"/> 242 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 243 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 244 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 245 </input> 246 </xsl:template> 247 248 249 250 <!-- Geometry. --> 251 252 <xsl:template match="property[@name='geometry']"> 253 <xsl:apply-templates select="rect/*[1]"> 254 <xsl:with-param name="style">position: absolute</xsl:with-param> 255 </xsl:apply-templates> 256 </xsl:template> 257 258 <xsl:template name="make-geometry"> 259 <xsl:param name="style"/> 260 <xsl:variable name="dimension" select="following-sibling::*[1]"/> 261 <xsl:choose> 262 <xsl:when test="not($dimension)"> 263 <xsl:attribute name="style"><xsl:value-of select="$style"/></xsl:attribute> 264 </xsl:when> 265 <xsl:otherwise> 266 <xsl:apply-templates select="$dimension"> 267 <xsl:with-param name="style" select="$style"/> 268 </xsl:apply-templates> 269 </xsl:otherwise> 270 </xsl:choose> 271 </xsl:template> 272 273 <xsl:template match="x"> 274 <xsl:param name="style"/> 275 <xsl:call-template name="make-geometry"> 276 <xsl:with-param name="style"><xsl:value-of select="$style"/>; left: <xsl:value-of select="text()"/>px</xsl:with-param> 277 </xsl:call-template> 278 </xsl:template> 279 280 <xsl:template match="y"> 281 <xsl:param name="style"/> 282 <xsl:call-template name="make-geometry"> 283 <xsl:with-param name="style"><xsl:value-of select="$style"/>; top: <xsl:value-of select="text()"/>px</xsl:with-param> 284 </xsl:call-template> 285 </xsl:template> 286 287 <xsl:template match="width"> 288 <xsl:param name="style"/> 289 <xsl:call-template name="make-geometry"> 290 <xsl:with-param name="style"><xsl:value-of select="$style"/>; width: <xsl:value-of select="text()"/>px</xsl:with-param> 291 </xsl:call-template> 292 </xsl:template> 293 294 <xsl:template match="height"> 295 <xsl:param name="style"/> 296 <xsl:call-template name="make-geometry"> 297 <xsl:with-param name="style"><xsl:value-of select="$style"/>; height: <xsl:value-of select="text()"/>px</xsl:with-param> 298 </xsl:call-template> 299 </xsl:template> 300 301 302 303 <!-- Identification. --> 304 305 <xsl:template match="property[@name='name']"> 306 </xsl:template> 307 308 309 310 <!-- Labels and values. --> 311 312 <xsl:template match="property[@name='text']"> 313 </xsl:template> 314 315 316 317 <!-- Captions. --> 318 319 <xsl:template match="property[@name='caption']"> 320 </xsl:template> 321 322 323 324 <!-- Copy attributes. --> 325 326 <xsl:template match="@*"> 327 <xsl:copy> 328 <xsl:apply-templates select="node()"/> 329 </xsl:copy> 330 </xsl:template> 331 332 </xsl:stylesheet>