-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathxsd
162 lines (149 loc) · 6.66 KB
/
xsd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?xml version="1.0" encoding="UTF-8"?>
<!--
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (C) 2014 Open Microscopy Environment
# Massachusetts Institute of Technology,
# National Institutes of Health,
# University of Dundee,
# University of Wisconsin at Madison
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-->
<!--
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Written by: Andrew Patterson: ajpatterson at lifesci.dundee.ac.uk
# Generated by: templates/xsd. Please do not edit!
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://exslt.org/math"
exclude-result-prefixes="xs"
version="1.0"
xmlns:py="http://genshi.edgewall.org/">
<!-- getDefault function (AttributeName, NodeName, ParentNodeName?) -->
<!-- returns the default as string -->
<xsl:template name="GetDefaultUnit">
<xsl:param name="theAttributeName"/>
<xsl:param name="theElementName"/>
<xsl:choose>
<!-- codegen begin - defaults -->
<py:for each="field in fields">
<xsl:when test="$$theAttributeName = '$field.NAME' and $$theElementName = '$field.CLASS'">$field.DEFAULT</xsl:when>
</py:for>
<!-- codegen end - defaults -->
<xsl:otherwise>
<xsl:message terminate="yes">OME-XSLT: units-conversion.xsl - ERROR - GetDefaultUnit, the default for [<xsl:value-of select="$$theAttributeName"/>] in element [<xsl:value-of select="$$theElementName"/>] is not supported.</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- returns the value in the default units -->
<!-- error and terminate if conversion not possible e.g. pixel->nm -->
<xsl:template name="ConvertValueToDefault">
<xsl:param name="theValue"/>
<xsl:param name="theCurrentUnit"/>
<xsl:param name="theAttributeName"/>
<xsl:param name="theElementName"/>
<xsl:message>OME-XSLT: units-conversion.xsl - Message - ConvertValueToDefault, (<xsl:value-of select="$$theValue"/>, <xsl:value-of select="$$theCurrentUnit"/>, <xsl:value-of select="$$theAttributeName"/>, <xsl:value-of select="$$theElementName"/>).</xsl:message>
<xsl:choose>
<xsl:when test="$$theCurrentUnit = ''">
<!-- Already using default units so no conversion necessary -->
<xsl:value-of select="$$theValue"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="ConvertValueToUnit">
<xsl:with-param name="theValue"><xsl:value-of select="$$theValue"/></xsl:with-param>
<xsl:with-param name="theCurrentUnit"><xsl:value-of select="$$theCurrentUnit"/></xsl:with-param>
<xsl:with-param name="theNewUnit">
<xsl:call-template name="GetDefaultUnit">
<xsl:with-param name="theAttributeName"><xsl:value-of select="$$theAttributeName"/></xsl:with-param>
<xsl:with-param name="theElementName"><xsl:value-of select="$$theElementName"/></xsl:with-param>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="ConvertValueToUnit">
<xsl:param name="theValue"/>
<xsl:param name="theCurrentUnit"/>
<xsl:param name="theNewUnit"/>
<xsl:choose>
<xsl:when test="$$theNewUnit = ''">
<xsl:message terminate="yes">OME-XSLT: units-conversion.xsl - ERROR - ConvertValueToUnit, cannot perform conversion of [<xsl:value-of select="$$theCurrentUnit"/>] to an unknown unit.</xsl:message>
</xsl:when>
<xsl:when test="$$theNewUnit = $$theCurrentUnit"><xsl:value-of select="$$theValue"/></xsl:when>
<!-- codegen begin - convert -->
<?python
def conversion(cfrom, cto, equation):
if cfrom == cto:
return "$theValue"
def Add(*c):
sb = "+".join([str(x) for x in c])
return "(%s)" % sb
def Int(i):
return str(i)
def Mul(*c):
sb = "*".join([str(x) for x in c])
return "(%s)" % sb
def Pow(base, exp):
return "math:power(%s, %s)" % (base, exp)
def Rat(n, d):
return "(%s div %s)" % (n, d)
def Sym(x):
return "$theValue"
from math import pi
return str(eval(equation))
?>
<py:for each="name, unit in sorted(items.items())">
<py:for each="cfrom in unit">
<!--! Same block as in templates/blitz.java -->
<xsl:when test="$$theCurrentUnit = '$cfrom.SYMBOL'">
<xsl:choose>
<xsl:when test="$$theNewUnit = 'UNKNOWN%SYMBOL'"><xsl:value-of select="ERROR"/></xsl:when>
<py:for each="cto in unit">
<py:if test="cfrom != cto">
<py:with vars="equation = equations.get(name.upper(), {}).get(cfrom.CODE, {}).get(cto.CODE, {})">
<py:if test="equation">
<xsl:when test="$$theNewUnit = '$cto.SYMBOL'"><xsl:value-of select="${conversion(cfrom, cto, equation)}"/></xsl:when>
</py:if>
</py:with>
</py:if>
</py:for>
<xsl:otherwise>
<xsl:message terminate="yes">OME-XSLT: units-conversion.xsl - ERROR - ConvertValueToUnit, cannot perform conversion, [<xsl:value-of select="$$theCurrentUnit"/>] to [<xsl:value-of select="$$theNewUnit"/>] is not supported.</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$$theNewUnit = '°C'">
<xsl:choose>
<xsl:when test="$$theCurrentUnit = '°F'"><xsl:value-of select="(($$theValue - 32) * 5) div 9"/></xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">OME-XSLT: units-conversion.xsl - ERROR - ConvertValueToUnit, cannot perform conversion, [<xsl:value-of select="$$theCurrentUnit"/>] to [<xsl:value-of select="$$theNewUnit"/>] is not supported.</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
</py:for>
</py:for>
<!-- codegen end - convert -->
<xsl:otherwise>
<xsl:message terminate="yes">OME-XSLT: units-conversion.xsl - ERROR - ConvertValueToUnit, cannot perform conversion from any unit to [<xsl:value-of select="$$theNewUnit"/>].</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>