You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

propinc.xsl 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <!--
  2. $Id$
  3. ============================================================================
  4. The Apache Software License, Version 1.1
  5. ============================================================================
  6. Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  7. Redistribution and use in source and binary forms, with or without modifica-
  8. tion, are permitted provided that the following conditions are met:
  9. 1. Redistributions of source code must retain the above copyright notice,
  10. this list of conditions and the following disclaimer.
  11. 2. Redistributions in binary form must reproduce the above copyright notice,
  12. this list of conditions and the following disclaimer in the documentation
  13. and/or other materials provided with the distribution.
  14. 3. The end-user documentation included with the redistribution, if any, must
  15. include the following acknowledgment: "This product includes software
  16. developed by the Apache Software Foundation (http://www.apache.org/)."
  17. Alternately, this acknowledgment may appear in the software itself, if
  18. and wherever such third-party acknowledgments normally appear.
  19. 4. The names "FOP" and "Apache Software Foundation" must not be used to
  20. endorse or promote products derived from this software without prior
  21. written permission. For written permission, please contact
  22. apache@apache.org.
  23. 5. Products derived from this software may not be called "Apache", nor may
  24. "Apache" appear in their name, without prior written permission of the
  25. Apache Software Foundation.
  26. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  27. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  28. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  29. APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  30. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  31. DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  32. OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  33. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  35. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. ============================================================================
  37. This software consists of voluntary contributions made by many individuals
  38. on behalf of the Apache Software Foundation and was originally created by
  39. James Tauber <jtauber@jtauber.com>. For more information on the Apache
  40. Software Foundation, please see <http://www.apache.org/>.
  41. -->
  42. <xsl:stylesheet version="1.0"
  43. xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
  44. <xsl:key name="genericref" match="property[@type='generic']" use="class-name"/>
  45. <xsl:key name="shorthandref" match="property" use="name"/>
  46. <xsl:template name="capfirst">
  47. <xsl:param name="str"/>
  48. <xsl:variable name="lcletters" select="'abcdefghijklmnopqrstuvwxyz'" />
  49. <xsl:variable name="ucletters" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
  50. <xsl:value-of select="concat(translate(substring($str, 1, 1),
  51. $lcletters, $ucletters), substring($str, 2))"/>
  52. </xsl:template>
  53. <xsl:template name="makeClassName">
  54. <xsl:param name="propstr"/>
  55. <xsl:choose>
  56. <xsl:when test="contains($propstr, '-')">
  57. <xsl:call-template name="capfirst">
  58. <xsl:with-param name="str" select="substring-before($propstr, '-')"/>
  59. </xsl:call-template>
  60. <xsl:call-template name="makeClassName">
  61. <xsl:with-param name="propstr" select="substring-after($propstr, '-')"/>
  62. </xsl:call-template>
  63. </xsl:when>
  64. <xsl:otherwise>
  65. <xsl:call-template name="capfirst">
  66. <xsl:with-param name="str" select="$propstr"/>
  67. </xsl:call-template>
  68. </xsl:otherwise>
  69. </xsl:choose>
  70. </xsl:template>
  71. <!-- Generate enumeration constants for FO's, Properties, etc. -->
  72. <xsl:template name="makeEnumConstant">
  73. <xsl:param name="propstr"/>
  74. <xsl:variable name="lcletters" select="'abcdefghijklmnopqrstuvwxyz-:'" />
  75. <xsl:variable name="ucletters" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ__'" />
  76. <xsl:value-of select="translate($propstr, $lcletters, $ucletters)"/>
  77. </xsl:template>
  78. <!-- The name of the subclass of Property to be created -->
  79. <xsl:template name="propclass">
  80. <xsl:param name="prop" select="."/>
  81. <xsl:choose>
  82. <xsl:when test="$prop/datatype">
  83. <xsl:value-of select="$prop/datatype"/><xsl:text>Property</xsl:text>
  84. </xsl:when>
  85. <xsl:when test="$prop/use-generic[@ispropclass='true']">
  86. <xsl:value-of select="$prop/use-generic"/>
  87. </xsl:when>
  88. <xsl:when test="$prop/use-generic">
  89. <!-- If no datatype child, then the prop must use the same datatype as
  90. its template. -->
  91. <xsl:call-template name="propclass">
  92. <xsl:with-param name="prop"
  93. select="key('genericref', $prop/use-generic)"/>
  94. </xsl:call-template>
  95. </xsl:when>
  96. <xsl:otherwise>
  97. <!-- ERROR -->
  98. <xsl:message terminate="yes">
  99. No datatype found for property: <xsl:value-of select="$prop/name"/>
  100. </xsl:message>
  101. </xsl:otherwise>
  102. </xsl:choose>
  103. </xsl:template>
  104. <!-- return a boolean value -->
  105. <xsl:template name="hasEnum">
  106. <xsl:param name="prop" select="."/>
  107. <xsl:choose>
  108. <xsl:when test="$prop/enumeration">true</xsl:when>
  109. <xsl:when test="$prop/use-generic">
  110. <!-- If no datatype child, then the prop must use the same datatype as
  111. its template. -->
  112. <xsl:call-template name="hasEnum">
  113. <xsl:with-param name="prop"
  114. select="key('genericref', $prop/use-generic)"/>
  115. </xsl:call-template>
  116. </xsl:when>
  117. <xsl:otherwise>false</xsl:otherwise>
  118. </xsl:choose>
  119. </xsl:template>
  120. <!-- return a boolean value -->
  121. <xsl:template name="hasSubpropEnum">
  122. <xsl:param name="prop" select="."/>
  123. <xsl:choose>
  124. <xsl:when test="$prop/compound/subproperty/enumeration">true</xsl:when>
  125. <xsl:when test="$prop/use-generic">
  126. <!-- If no datatype child, then the prop must use the same datatype as
  127. its template. -->
  128. <xsl:call-template name="hasSubpropEnum">
  129. <xsl:with-param name="prop"
  130. select="key('genericref', $prop/use-generic)"/>
  131. </xsl:call-template>
  132. </xsl:when>
  133. <xsl:when test="$prop/compound/subproperty/use-generic">
  134. <xsl:for-each select="$prop/compound/subproperty[use-generic]">
  135. <xsl:call-template name="hasEnum">
  136. <xsl:with-param name="prop"
  137. select="key('genericref', use-generic)"/>
  138. </xsl:call-template>
  139. </xsl:for-each>
  140. </xsl:when>
  141. <xsl:otherwise>false</xsl:otherwise>
  142. </xsl:choose>
  143. </xsl:template>
  144. </xsl:stylesheet>