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