1.1 --- a/XSLForms/XSL/QtDesigner.xsl Mon Jun 22 21:45:16 2009 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,373 +0,0 @@
1.4 -<?xml version="1.0"?>
1.5 -<!--
1.6 -An experimental Qt Designer form conversion stylesheet.
1.7 -
1.8 -Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk>
1.9 -
1.10 -This program is free software; you can redistribute it and/or modify it under
1.11 -the terms of the GNU Lesser General Public License as published by the Free
1.12 -Software Foundation; either version 3 of the License, or (at your option) any
1.13 -later version.
1.14 -
1.15 -This program is distributed in the hope that it will be useful, but WITHOUT
1.16 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.17 -FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
1.18 -details.
1.19 -
1.20 -You should have received a copy of the GNU Lesser General Public License along
1.21 -with this program. If not, see <http://www.gnu.org/licenses/>.
1.22 --->
1.23 -<xsl:stylesheet version="1.0"
1.24 - xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
1.25 - xmlns:set="http://exslt.org/sets"
1.26 - xmlns:math="http://exslt.org/math"
1.27 - xmlns:template="http://www.boddie.org.uk/ns/xmltools/template">
1.28 -
1.29 - <xsl:output indent="yes"/>
1.30 -
1.31 -
1.32 -
1.33 - <!-- Start at the top, producing a template file. -->
1.34 -
1.35 - <xsl:template match="UI">
1.36 - <html xmlns="http://www.w3.org/1999/xhtml">
1.37 - <head>
1.38 - <title><xsl:value-of select="widget/property[@name='caption']/string/text()"/></title>
1.39 - <link xmlns:xlink="http://www.w3.org/1999/xlink" href="styles/styles.css" rel="stylesheet" type="text/css" />
1.40 - <script type="text/javascript" src="scripts/sarissa.js"> </script>
1.41 - <script type="text/javascript" src="scripts/XSLForms.js"> </script>
1.42 - </head>
1.43 - <body>
1.44 - <form method="post">
1.45 - <xsl:apply-templates select="widget"/>
1.46 - </form>
1.47 - </body>
1.48 - </html>
1.49 - </xsl:template>
1.50 -
1.51 -
1.52 -
1.53 - <!-- Reproduce the layout. -->
1.54 -
1.55 - <xsl:template match="grid">
1.56 - <xsl:variable name="grid" select="."/>
1.57 - <table xmlns="http://www.w3.org/1999/xhtml" width="100%">
1.58 - <!-- Get the row numbers in ascending order. -->
1.59 - <xsl:for-each select="set:distinct($grid/*/@row)">
1.60 - <xsl:sort select="." data-type="number" order="ascending"/>
1.61 - <xsl:variable name="row" select="."/>
1.62 - <tr>
1.63 - <!-- Get all elements in the row, ordered by column number. -->
1.64 - <xsl:call-template name="grid-column">
1.65 - <xsl:with-param name="column" select="math:min($grid/*[@row=$row]/@column)"/>
1.66 - <xsl:with-param name="row" select="$row"/>
1.67 - <xsl:with-param name="grid" select="$grid"/>
1.68 - <xsl:with-param name="last-column">-1</xsl:with-param>
1.69 - </xsl:call-template>
1.70 - </tr>
1.71 - </xsl:for-each>
1.72 - </table>
1.73 - </xsl:template>
1.74 -
1.75 - <xsl:template name="grid-column">
1.76 - <xsl:param name="column"/>
1.77 - <xsl:param name="row"/>
1.78 - <xsl:param name="grid"/>
1.79 - <xsl:param name="last-column"/>
1.80 - <xsl:param name="last-colspan">1</xsl:param>
1.81 - <!-- Insert missing cells. -->
1.82 - <xsl:if test="$column != $last-column + $last-colspan">
1.83 - <xsl:variable name="spanned-columns" select="$grid/*[$row > @row and @row + @rowspan > $row and @column > $last-column and $column > @column]/@column"/>
1.84 - <xsl:choose>
1.85 - <xsl:when test="count($spanned-columns) != 0">
1.86 - <xsl:variable name="last-spanned-column" select="math:highest($spanned-columns)"/>
1.87 - <xsl:variable name="last-spanned-colspan" select="$last-spanned-column/../@colspan"/>
1.88 - <xsl:if test="$column != $last-spanned-column + $last-spanned-colspan">
1.89 - <td colspan="{$column - $last-spanned-column - $last-spanned-colspan}" xmlns="http://www.w3.org/1999/xhtml">
1.90 - </td>
1.91 - </xsl:if>
1.92 - </xsl:when>
1.93 - <xsl:otherwise>
1.94 - <td colspan="{$column - $last-column - $last-colspan}" xmlns="http://www.w3.org/1999/xhtml">
1.95 - </td>
1.96 - </xsl:otherwise>
1.97 - </xsl:choose>
1.98 - </xsl:if>
1.99 - <!-- Remember useful information. -->
1.100 - <xsl:variable name="this-column" select="$grid/*[@row=$row and @column=$column]"/>
1.101 - <xsl:variable name="this-colspan" select="$this-column/@colspan"/>
1.102 - <!-- Insert this cell. -->
1.103 - <td xmlns="http://www.w3.org/1999/xhtml">
1.104 - <!-- Add colspan and rowspan details. -->
1.105 - <xsl:apply-templates select="$this-colspan|$this-column/@rowspan"/>
1.106 - <!-- Transform the element. -->
1.107 - <xsl:apply-templates select="$this-column"/>
1.108 - </td>
1.109 - <!-- Find remaining cells in this row. -->
1.110 - <xsl:if test="count($grid/*[@row=$row and @column > $column]) > 0">
1.111 - <xsl:choose>
1.112 - <xsl:when test="$this-colspan">
1.113 - <xsl:call-template name="grid-column">
1.114 - <xsl:with-param name="column" select="math:min($grid/*[@row=$row and @column > $column]/@column)"/>
1.115 - <xsl:with-param name="row" select="$row"/>
1.116 - <xsl:with-param name="grid" select="$grid"/>
1.117 - <xsl:with-param name="last-column" select="$column"/>
1.118 - <xsl:with-param name="last-colspan" select="$this-colspan"/>
1.119 - </xsl:call-template>
1.120 - </xsl:when>
1.121 - <xsl:otherwise>
1.122 - <xsl:call-template name="grid-column">
1.123 - <xsl:with-param name="column" select="math:min($grid/*[@row=$row and @column > $column]/@column)"/>
1.124 - <xsl:with-param name="row" select="$row"/>
1.125 - <xsl:with-param name="grid" select="$grid"/>
1.126 - <xsl:with-param name="last-column" select="$column"/>
1.127 - </xsl:call-template>
1.128 - </xsl:otherwise>
1.129 - </xsl:choose>
1.130 - </xsl:if>
1.131 - </xsl:template>
1.132 -
1.133 - <xsl:template match="spacer">
1.134 - </xsl:template>
1.135 -
1.136 - <xsl:template match="vbox">
1.137 - <xsl:apply-templates select="*[not(local-name() = 'property')]"/>
1.138 - </xsl:template>
1.139 -
1.140 - <xsl:template match="hbox">
1.141 - <xsl:apply-templates select="*[not(local-name() = 'property')]"/>
1.142 - </xsl:template>
1.143 -
1.144 - <xsl:template match="widget">
1.145 - <xsl:apply-templates select="property[@name='geometry']"/>
1.146 - <xsl:apply-templates select="*[not(local-name() = 'property')]"/>
1.147 - </xsl:template>
1.148 -
1.149 - <!-- Container widgets. -->
1.150 -
1.151 - <xsl:template match="widget[@class='QFrame']">
1.152 - <div xmlns="http://www.w3.org/1999/xhtml">
1.153 - <xsl:variable name="name-prop" select="property[@name='name']"/>
1.154 - <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
1.155 - <xsl:apply-templates select="property[@name='geometry']"/>
1.156 - <xsl:apply-templates select="*[not(local-name() = 'property')]"/>
1.157 - </div>
1.158 - </xsl:template>
1.159 -
1.160 - <xsl:template match="widget[@class='QTabWidget']">
1.161 - <xsl:variable name="name-prop" select="property[@name='name']"/>
1.162 - <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
1.163 - <xsl:apply-templates select="property[@name='geometry']"/>
1.164 - <xsl:apply-templates select="*[not(local-name() = 'property')]"/>
1.165 - </xsl:template>
1.166 -
1.167 - <xsl:template match="widget[@class='QWidgetStack']">
1.168 - <xsl:variable name="name-prop" select="property[@name='name']"/>
1.169 - <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
1.170 - <xsl:apply-templates select="property[@name='geometry']"/>
1.171 - <xsl:apply-templates select="*[not(local-name() = 'property')]"/>
1.172 - </xsl:template>
1.173 -
1.174 - <xsl:template match="widget[@class='QWidget']">
1.175 - <!-- NOTE: Suppress overriding of names. -->
1.176 - <xsl:if test="not(../@class) or ../@class != 'QTabWidget'">
1.177 - <xsl:variable name="name-prop" select="property[@name='name']"/>
1.178 - <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
1.179 - </xsl:if>
1.180 - <xsl:apply-templates select="property[@name='geometry']"/>
1.181 - <xsl:apply-templates select="*[not(local-name() = 'property') and not(local-name() = 'attribute')]"/>
1.182 - </xsl:template>
1.183 -
1.184 - <!-- Specific widgets. -->
1.185 -
1.186 - <xsl:template match="widget[@class='QComboBox']">
1.187 - <select xmlns="http://www.w3.org/1999/xhtml">
1.188 - <xsl:variable name="name-prop" select="property[@name='name']"/>
1.189 - <xsl:variable name="field-name" select="$name-prop/cstring/text()"/>
1.190 - <!-- NOTE: Adding _enum suffix. -->
1.191 - <xsl:variable name="enum-name" select="concat($name-prop/cstring/text(), '_enum')"/>
1.192 - <xsl:attribute name="template:multiple-choice-field"><xsl:value-of select="$field-name"/>,value</xsl:attribute>
1.193 - <xsl:attribute name="name"><xsl:value-of select="$field-name"/></xsl:attribute>
1.194 - <xsl:apply-templates select="item">
1.195 - <xsl:with-param name="enum-name" select="$enum-name"/>
1.196 - </xsl:apply-templates>
1.197 - </select>
1.198 - </xsl:template>
1.199 -
1.200 - <xsl:template match="widget[@class='QListBox']">
1.201 - <select xmlns="http://www.w3.org/1999/xhtml" multiple="multiple">
1.202 - <xsl:variable name="name-prop" select="property[@name='name']"/>
1.203 - <xsl:variable name="field-name" select="$name-prop/cstring/text()"/>
1.204 - <!-- NOTE: Adding _enum suffix. -->
1.205 - <xsl:variable name="enum-name" select="concat($name-prop/cstring/text(), '_enum')"/>
1.206 - <xsl:attribute name="template:multiple-choice-list-field"><xsl:value-of select="$field-name"/>,<xsl:value-of select="$enum-name"/></xsl:attribute>
1.207 - <xsl:attribute name="name"><xsl:value-of select="$field-name"/></xsl:attribute>
1.208 - <xsl:apply-templates select="item">
1.209 - <xsl:with-param name="enum-name" select="$enum-name"/>
1.210 - <xsl:with-param name="item-type">list</xsl:with-param>
1.211 - </xsl:apply-templates>
1.212 - </select>
1.213 - </xsl:template>
1.214 -
1.215 - <xsl:template match="item">
1.216 - <xsl:param name="enum-name"/>
1.217 - <xsl:param name="item-type"/>
1.218 - <option xmlns="http://www.w3.org/1999/xhtml">
1.219 - <xsl:choose>
1.220 - <xsl:when test="$item-type = 'list'">
1.221 - <xsl:attribute name="template:multiple-choice-list-value"><xsl:value-of select="$enum-name"/>,value,selected</xsl:attribute>
1.222 - </xsl:when>
1.223 - <xsl:otherwise>
1.224 - <xsl:attribute name="template:multiple-choice-value"><xsl:value-of select="$enum-name"/>,value,selected</xsl:attribute>
1.225 - </xsl:otherwise>
1.226 - </xsl:choose>
1.227 - <xsl:variable name="value-prop" select="property[@name='text']"/>
1.228 - <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute>
1.229 - <xsl:value-of select="$value-prop/string/text()"/>
1.230 - </option>
1.231 - </xsl:template>
1.232 -
1.233 - <xsl:template match="widget[@class='QLabel']">
1.234 - <xsl:variable name="value-prop" select="property[@name='text']"/>
1.235 - <!-- NOTE: Permitting element generation from the text. -->
1.236 - <xsl:value-of disable-output-escaping="yes" select="$value-prop/string/text()"/>
1.237 - </xsl:template>
1.238 -
1.239 - <xsl:template match="widget[@class='QPushButton']">
1.240 - <input xmlns="http://www.w3.org/1999/xhtml" type="submit">
1.241 - <xsl:variable name="name-prop" select="property[@name='name']"/>
1.242 - <xsl:variable name="field-name" select="$name-prop/cstring/text()"/>
1.243 - <xsl:variable name="value-prop" select="property[@name='text']"/>
1.244 - <xsl:choose>
1.245 - <xsl:when test="starts-with($field-name, 'add_')">
1.246 - <xsl:variable name="affected-element" select="substring-after($field-name, 'add_')"/>
1.247 - <xsl:attribute name="template:selector-field"><xsl:value-of select="$field-name"/>,<xsl:value-of select="$affected-element"/></xsl:attribute>
1.248 - </xsl:when>
1.249 - <xsl:when test="starts-with($field-name, 'remove_')">
1.250 - <xsl:variable name="affected-element" select="substring-after($field-name, 'remove_')"/>
1.251 - <xsl:attribute name="template:selector-field"><xsl:value-of select="$field-name"/>,<xsl:value-of select="$affected-element"/></xsl:attribute>
1.252 - </xsl:when>
1.253 - <xsl:otherwise>
1.254 - <xsl:attribute name="template:selector-field"><xsl:value-of select="$field-name"/></xsl:attribute>
1.255 - </xsl:otherwise>
1.256 - </xsl:choose>
1.257 - <xsl:attribute name="name"><xsl:value-of select="$field-name"/></xsl:attribute>
1.258 - <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute>
1.259 - </input>
1.260 - </xsl:template>
1.261 -
1.262 - <xsl:template match="widget[@class='QLineEdit']">
1.263 - <input xmlns="http://www.w3.org/1999/xhtml" type="text">
1.264 - <xsl:variable name="name-prop" select="property[@name='name']"/>
1.265 - <xsl:variable name="value-prop" select="property[@name='text']"/>
1.266 - <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
1.267 - <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
1.268 - <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute>
1.269 - </input>
1.270 - </xsl:template>
1.271 -
1.272 - <xsl:template match="widget[@class='QTextEdit']">
1.273 - <textarea xmlns="http://www.w3.org/1999/xhtml">
1.274 - <xsl:variable name="name-prop" select="property[@name='name']"/>
1.275 - <xsl:variable name="value-prop" select="property[@name='text']"/>
1.276 - <xsl:attribute name="template:attribute-area"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
1.277 - <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
1.278 - <xsl:value-of select="$value-prop/string/text()"/>
1.279 - </textarea>
1.280 - </xsl:template>
1.281 -
1.282 - <xsl:template match="widget[@class='QRadioButton']">
1.283 - <input xmlns="http://www.w3.org/1999/xhtml" type="radio">
1.284 - <xsl:variable name="name-prop" select="property[@name='name']"/>
1.285 - <xsl:variable name="value-prop" select="property[@name='text']"/>
1.286 - <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
1.287 - <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute>
1.288 - <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute>
1.289 - </input>
1.290 - </xsl:template>
1.291 -
1.292 -
1.293 -
1.294 - <!-- Geometry. -->
1.295 -
1.296 - <xsl:template match="property[@name='geometry']">
1.297 - <xsl:apply-templates select="rect/*[1]">
1.298 - <xsl:with-param name="style">position: absolute</xsl:with-param>
1.299 - </xsl:apply-templates>
1.300 - </xsl:template>
1.301 -
1.302 - <xsl:template name="make-geometry">
1.303 - <xsl:param name="style"/>
1.304 - <xsl:variable name="dimension" select="following-sibling::*[1]"/>
1.305 - <xsl:choose>
1.306 - <xsl:when test="not($dimension)">
1.307 - <xsl:attribute name="style"><xsl:value-of select="$style"/></xsl:attribute>
1.308 - </xsl:when>
1.309 - <xsl:otherwise>
1.310 - <xsl:apply-templates select="$dimension">
1.311 - <xsl:with-param name="style" select="$style"/>
1.312 - </xsl:apply-templates>
1.313 - </xsl:otherwise>
1.314 - </xsl:choose>
1.315 - </xsl:template>
1.316 -
1.317 - <xsl:template match="x">
1.318 - <xsl:param name="style"/>
1.319 - <xsl:call-template name="make-geometry">
1.320 - <xsl:with-param name="style"><xsl:value-of select="$style"/>; left: <xsl:value-of select="text()"/>px</xsl:with-param>
1.321 - </xsl:call-template>
1.322 - </xsl:template>
1.323 -
1.324 - <xsl:template match="y">
1.325 - <xsl:param name="style"/>
1.326 - <xsl:call-template name="make-geometry">
1.327 - <xsl:with-param name="style"><xsl:value-of select="$style"/>; top: <xsl:value-of select="text()"/>px</xsl:with-param>
1.328 - </xsl:call-template>
1.329 - </xsl:template>
1.330 -
1.331 - <xsl:template match="width">
1.332 - <xsl:param name="style"/>
1.333 - <xsl:call-template name="make-geometry">
1.334 - <xsl:with-param name="style"><xsl:value-of select="$style"/>; width: <xsl:value-of select="text()"/>px</xsl:with-param>
1.335 - </xsl:call-template>
1.336 - </xsl:template>
1.337 -
1.338 - <xsl:template match="height">
1.339 - <xsl:param name="style"/>
1.340 - <xsl:call-template name="make-geometry">
1.341 - <xsl:with-param name="style"><xsl:value-of select="$style"/>; height: <xsl:value-of select="text()"/>px</xsl:with-param>
1.342 - </xsl:call-template>
1.343 - </xsl:template>
1.344 -
1.345 -
1.346 -
1.347 - <!-- Identification. -->
1.348 -
1.349 - <xsl:template match="property[@name='name']">
1.350 - </xsl:template>
1.351 -
1.352 -
1.353 -
1.354 - <!-- Labels and values. -->
1.355 -
1.356 - <xsl:template match="property[@name='text']">
1.357 - </xsl:template>
1.358 -
1.359 -
1.360 -
1.361 - <!-- Captions. -->
1.362 -
1.363 - <xsl:template match="property[@name='caption']">
1.364 - </xsl:template>
1.365 -
1.366 -
1.367 -
1.368 - <!-- Copy attributes. -->
1.369 -
1.370 - <xsl:template match="@*">
1.371 - <xsl:copy>
1.372 - <xsl:apply-templates select="node()"/>
1.373 - </xsl:copy>
1.374 - </xsl:template>
1.375 -
1.376 -</xsl:stylesheet>