| 1 |
<!-- |
| 2 |
Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 |
contributor license agreements. See the NOTICE file distributed with |
| 4 |
this work for additional information regarding copyright ownership. |
| 5 |
The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 |
(the "License"); you may not use this file except in compliance with |
| 7 |
the License. You may obtain a copy of the License at |
| 8 |
|
| 9 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
|
| 11 |
Unless required by applicable law or agreed to in writing, software |
| 12 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
See the License for the specific language governing permissions and |
| 15 |
limitations under the License. |
| 16 |
--> |
| 17 |
<!-- $Id$ --> |
| 18 |
<xsl:stylesheet version="1.0" |
| 19 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > |
| 20 |
|
| 21 |
<xsl:key name="genericref" match="property[@type='generic']" use="class-name"/> |
| 22 |
<xsl:key name="shorthandref" match="property" use="name"/> |
| 23 |
|
| 24 |
<xsl:template name="capfirst"> |
| 25 |
<xsl:param name="str"/> |
| 26 |
<xsl:variable name="lcletters" select="'abcdefghijklmnopqrstuvwxyz'" /> |
| 27 |
<xsl:variable name="ucletters" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" /> |
| 28 |
<xsl:value-of select="concat(translate(substring($str, 1, 1), |
| 29 |
$lcletters, $ucletters), substring($str, 2))"/> |
| 30 |
</xsl:template> |
| 31 |
|
| 32 |
<xsl:template name="makeClassName"> |
| 33 |
<xsl:param name="propstr"/> |
| 34 |
<xsl:choose> |
| 35 |
<xsl:when test="contains($propstr, '-')"> |
| 36 |
<xsl:call-template name="capfirst"> |
| 37 |
<xsl:with-param name="str" select="substring-before($propstr, '-')"/> |
| 38 |
</xsl:call-template> |
| 39 |
<xsl:call-template name="makeClassName"> |
| 40 |
<xsl:with-param name="propstr" select="substring-after($propstr, '-')"/> |
| 41 |
</xsl:call-template> |
| 42 |
</xsl:when> |
| 43 |
<xsl:otherwise> |
| 44 |
<xsl:call-template name="capfirst"> |
| 45 |
<xsl:with-param name="str" select="$propstr"/> |
| 46 |
</xsl:call-template> |
| 47 |
</xsl:otherwise> |
| 48 |
</xsl:choose> |
| 49 |
</xsl:template> |
| 50 |
|
| 51 |
<!-- Generate enumeration constants for FO's, Properties, etc. --> |
| 52 |
<xsl:template name="makeEnumConstant"> |
| 53 |
<xsl:param name="propstr"/> |
| 54 |
<xsl:variable name="lcletters" select="'abcdefghijklmnopqrstuvwxyz-:'" /> |
| 55 |
<xsl:variable name="ucletters" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ__'" /> |
| 56 |
<xsl:value-of select="translate($propstr, $lcletters, $ucletters)"/> |
| 57 |
</xsl:template> |
| 58 |
|
| 59 |
<!-- The name of the subclass of Property to be created --> |
| 60 |
<xsl:template name="propclass"> |
| 61 |
<xsl:param name="prop" select="."/> |
| 62 |
<xsl:choose> |
| 63 |
<xsl:when test="$prop/datatype"> |
| 64 |
<xsl:value-of select="$prop/datatype"/><xsl:text>Property</xsl:text> |
| 65 |
</xsl:when> |
| 66 |
<xsl:when test="$prop/use-generic[@ispropclass='true']"> |
| 67 |
<xsl:value-of select="$prop/use-generic"/> |
| 68 |
</xsl:when> |
| 69 |
<xsl:when test="$prop/use-generic"> |
| 70 |
<!-- If no datatype child, then the prop must use the same datatype as |
| 71 |
its template. --> |
| 72 |
<xsl:call-template name="propclass"> |
| 73 |
<xsl:with-param name="prop" |
| 74 |
select="key('genericref', $prop/use-generic)"/> |
| 75 |
</xsl:call-template> |
| 76 |
</xsl:when> |
| 77 |
<xsl:otherwise> |
| 78 |
<!-- ERROR --> |
| 79 |
<xsl:message terminate="yes"> |
| 80 |
No datatype found for property: <xsl:value-of select="$prop/name"/> |
| 81 |
</xsl:message> |
| 82 |
</xsl:otherwise> |
| 83 |
</xsl:choose> |
| 84 |
</xsl:template> |
| 85 |
|
| 86 |
<!-- return a boolean value --> |
| 87 |
<xsl:template name="hasEnum"> |
| 88 |
<xsl:param name="prop" select="."/> |
| 89 |
<xsl:choose> |
| 90 |
<xsl:when test="$prop/enumeration">true</xsl:when> |
| 91 |
<xsl:when test="$prop/use-generic"> |
| 92 |
<!-- If no datatype child, then the prop must use the same datatype as |
| 93 |
its template. --> |
| 94 |
<xsl:call-template name="hasEnum"> |
| 95 |
<xsl:with-param name="prop" |
| 96 |
select="key('genericref', $prop/use-generic)"/> |
| 97 |
</xsl:call-template> |
| 98 |
</xsl:when> |
| 99 |
<xsl:otherwise>false</xsl:otherwise> |
| 100 |
</xsl:choose> |
| 101 |
</xsl:template> |
| 102 |
|
| 103 |
<!-- return a boolean value --> |
| 104 |
<xsl:template name="hasSubpropEnum"> |
| 105 |
<xsl:param name="prop" select="."/> |
| 106 |
<xsl:choose> |
| 107 |
<xsl:when test="$prop/compound/subproperty/enumeration">true</xsl:when> |
| 108 |
<xsl:when test="$prop/use-generic"> |
| 109 |
<!-- If no datatype child, then the prop must use the same datatype as |
| 110 |
its template. --> |
| 111 |
<xsl:call-template name="hasSubpropEnum"> |
| 112 |
<xsl:with-param name="prop" |
| 113 |
select="key('genericref', $prop/use-generic)"/> |
| 114 |
</xsl:call-template> |
| 115 |
</xsl:when> |
| 116 |
<xsl:when test="$prop/compound/subproperty/use-generic"> |
| 117 |
<xsl:for-each select="$prop/compound/subproperty[use-generic]"> |
| 118 |
<xsl:call-template name="hasEnum"> |
| 119 |
<xsl:with-param name="prop" |
| 120 |
select="key('genericref', use-generic)"/> |
| 121 |
</xsl:call-template> |
| 122 |
</xsl:for-each> |
| 123 |
</xsl:when> |
| 124 |
<xsl:otherwise>false</xsl:otherwise> |
| 125 |
</xsl:choose> |
| 126 |
</xsl:template> |
| 127 |
|
| 128 |
</xsl:stylesheet> |