xform_4to5.xsl 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?xml version="1.0"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: fmmd
  5. (C) Copyright IBM Corp. 2003, 2013
  6. US Government Users Restricted Rights - Use, duplication or disclosure
  7. restricted by GSA ADP Schedule Contract with IBM Corp.
  8. -->
  9. <!--XSLT version 4-->
  10. <!--XSL Transformation from a schema v4 model to a valid BMT schema v5 model-->
  11. <xsl:stylesheet xmlns="http://www.developer.cognos.com/schemas/bmt/5/0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  12. <xsl:output encoding="utf-8" method="xml" indent="yes"/>
  13. <!--root match-->
  14. <xsl:template match="/">
  15. <!--make sure that this transformation is not performed on a schema v5 model-->
  16. <xsl:if test="/*[local-name() = 'project']/@xsi:schemaLocation = 'http://www.developer.cognos.com/schemas/bmt/5/0 BMTModelSpecification.xsd'">
  17. <xsl:message terminate="yes">The input file for this transformer must be a schema v4 model. You tried to use a schema v5 model.</xsl:message>
  18. </xsl:if>
  19. <xsl:apply-templates/>
  20. </xsl:template>
  21. <!--generic match, copies over the element unless it is redefined later in the file-->
  22. <xsl:template match="*">
  23. <xsl:element name="{name(.)}">
  24. <xsl:for-each select="@*">
  25. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  26. </xsl:for-each>
  27. <xsl:apply-templates/>
  28. </xsl:element>
  29. </xsl:template>
  30. <!--change the schema to v5 version-->
  31. <xsl:template match="*[local-name() = 'project']">
  32. <!--Count and store the number of 'parameterMaps' entities and 'securityViews' entities.-->
  33. <xsl:variable name="parameterMapFlag" select="count(*[name()='parameterMaps'])"/>
  34. <xsl:variable name="securityViewFlag" select="count(*[name()='securityViews'])"/>
  35. <xsl:element name="project" namespace="http://www.developer.cognos.com/schemas/bmt/5/0">
  36. <xsl:for-each select="@*">
  37. <xsl:choose>
  38. <!--change schema from v4 to v5-->
  39. <xsl:when test="name(.) = 'xsi:schemaLocation'">
  40. <xsl:attribute name="{name(.)}"><xsl:value-of select="'http://www.developer.cognos.com/schemas/bmt/5/0 BMTModelSpecification.xsd'"/></xsl:attribute>
  41. </xsl:when>
  42. <xsl:otherwise>
  43. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  44. </xsl:otherwise>
  45. </xsl:choose>
  46. </xsl:for-each>
  47. <xsl:apply-templates/>
  48. <!--If these don't exist, create them.-->
  49. <xsl:if test="not($parameterMapFlag &gt; 0)">
  50. <xsl:element name="parameterMaps"/>
  51. </xsl:if>
  52. <xsl:if test="not($securityViewFlag &gt; 0)">
  53. <xsl:element name="securityViews"/>
  54. </xsl:if>
  55. </xsl:element>
  56. </xsl:template>
  57. <!--remove securityView (but not securityViews container) completely-->
  58. <xsl:template match="*[local-name() = 'securityView']"/>
  59. <!--remove packages and subtree completely-->
  60. <xsl:template match="*[local-name() = 'packages']"/>
  61. <!--remove externalSource from parameterMap-->
  62. <xsl:template match="*[local-name() = 'externalSource']"/>
  63. <!--add mandatory elements to queryItem-->
  64. <xsl:template match="*[local-name() = 'queryItem']">
  65. <xsl:choose>
  66. <!--remove entire queryItem if it has a calculation-->
  67. <xsl:when test="./*[local-name() = 'calculation']">
  68. <!--do nothing-->
  69. </xsl:when>
  70. <xsl:otherwise>
  71. <xsl:element name="queryItem">
  72. <xsl:for-each select="@*">
  73. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  74. </xsl:for-each>
  75. <xsl:apply-templates select="*[local-name() = 'name']"/>
  76. <xsl:apply-templates select="*[local-name() = 'description']"/>
  77. <xsl:apply-templates select="*[local-name() = 'lastChanged']"/>
  78. <!--copy over columnName-->
  79. <xsl:apply-templates select="*[local-name() = 'columnName']"/>
  80. <!--properties are now mandatory; create with defaults if not already existing-->
  81. <xsl:choose>
  82. <xsl:when test="./*[local-name() = 'usage']">
  83. <xsl:apply-templates select="*[local-name() = 'usage']"/>
  84. </xsl:when>
  85. <xsl:otherwise>
  86. <xsl:element name="usage">kUsageIdentifier</xsl:element>
  87. </xsl:otherwise>
  88. </xsl:choose>
  89. <xsl:choose>
  90. <xsl:when test="./*[local-name() = 'format']">
  91. <xsl:apply-templates select="*[local-name() = 'format']"/>
  92. </xsl:when>
  93. <xsl:otherwise>
  94. <xsl:element name="format"/>
  95. </xsl:otherwise>
  96. </xsl:choose>
  97. <xsl:choose>
  98. <xsl:when test="./*[local-name() = 'datatype']">
  99. <xsl:apply-templates select="*[local-name() = 'datatype']"/>
  100. </xsl:when>
  101. <xsl:otherwise>
  102. <xsl:element name="datatype">kDataTypeDecimal</xsl:element>
  103. </xsl:otherwise>
  104. </xsl:choose>
  105. <xsl:choose>
  106. <xsl:when test="./*[local-name() = 'scale']">
  107. <xsl:apply-templates select="*[local-name() = 'scale']"/>
  108. </xsl:when>
  109. <xsl:otherwise>
  110. <xsl:element name="scale">0</xsl:element>
  111. </xsl:otherwise>
  112. </xsl:choose>
  113. <xsl:choose>
  114. <xsl:when test="./*[local-name() = 'size']">
  115. <xsl:apply-templates select="*[local-name() = 'size']"/>
  116. </xsl:when>
  117. <xsl:otherwise>
  118. <xsl:element name="size">20</xsl:element>
  119. </xsl:otherwise>
  120. </xsl:choose>
  121. <xsl:choose>
  122. <xsl:when test="./*[local-name() = 'nullable']">
  123. <xsl:apply-templates select="*[local-name() = 'nullable']"/>
  124. </xsl:when>
  125. <xsl:otherwise>
  126. <xsl:element name="nullable">0</xsl:element>
  127. </xsl:otherwise>
  128. </xsl:choose>
  129. <xsl:choose>
  130. <xsl:when test="./*[local-name() = 'regularAggregate']">
  131. <xsl:apply-templates select="*[local-name() = 'regularAggregate']"/>
  132. </xsl:when>
  133. <xsl:otherwise>
  134. <xsl:element name="regularAggregate">kAggregateRuleUnsupported</xsl:element>
  135. </xsl:otherwise>
  136. </xsl:choose>
  137. <xsl:choose>
  138. <xsl:when test="./*[local-name() = 'semiAggregate']">
  139. <xsl:apply-templates select="*[local-name() = 'semiAggregate']"/>
  140. </xsl:when>
  141. <xsl:otherwise>
  142. <xsl:element name="semiAggregate">kAggregateRuleUnsupported</xsl:element>
  143. </xsl:otherwise>
  144. </xsl:choose>
  145. <xsl:choose>
  146. <xsl:when test="./*[local-name() = 'precision']">
  147. <xsl:apply-templates select="*[local-name() = 'precision']"/>
  148. </xsl:when>
  149. <xsl:otherwise>
  150. <xsl:element name="precision">38</xsl:element>
  151. </xsl:otherwise>
  152. </xsl:choose>
  153. <xsl:choose>
  154. <xsl:when test="./*[local-name() = 'displayType']">
  155. <xsl:apply-templates select="*[local-name() = 'displayType']"/>
  156. </xsl:when>
  157. <xsl:otherwise>
  158. <xsl:element name="displayType">LargeText</xsl:element>
  159. </xsl:otherwise>
  160. </xsl:choose>
  161. <xsl:choose>
  162. <xsl:when test="./*[local-name() = 'isFew']">
  163. <xsl:apply-templates select="*[local-name() = 'isFew']"/>
  164. </xsl:when>
  165. <xsl:otherwise>
  166. <xsl:element name="isFew">false</xsl:element>
  167. </xsl:otherwise>
  168. </xsl:choose>
  169. <xsl:choose>
  170. <xsl:when test="./*[local-name() = 'isPromptLabel']">
  171. <xsl:apply-templates select="*[local-name() = 'isPromptLabel']"/>
  172. </xsl:when>
  173. <xsl:otherwise>
  174. <xsl:element name="isPromptLabel">false</xsl:element>
  175. </xsl:otherwise>
  176. </xsl:choose>
  177. <xsl:choose>
  178. <xsl:when test="./*[local-name() = 'collationSequenceName']">
  179. <xsl:apply-templates select="*[local-name() = 'collationSequenceName']"/>
  180. </xsl:when>
  181. <xsl:otherwise>
  182. <xsl:element name="collationSequenceName">C</xsl:element>
  183. </xsl:otherwise>
  184. </xsl:choose>
  185. <xsl:choose>
  186. <xsl:when test="./*[local-name() = 'collationSequenceLevel']">
  187. <xsl:apply-templates select="*[local-name() = 'collationSequenceLevel']"/>
  188. </xsl:when>
  189. <xsl:otherwise>
  190. <xsl:element name="collationSequenceLevel">2</xsl:element>
  191. </xsl:otherwise>
  192. </xsl:choose>
  193. <xsl:choose>
  194. <xsl:when test="./*[local-name() = 'originalCollationSequenceName']">
  195. <xsl:apply-templates select="*[local-name() = 'originalCollationSequenceName']"/>
  196. </xsl:when>
  197. <xsl:otherwise>
  198. <xsl:element name="originalCollationSequenceName">BINARY</xsl:element>
  199. </xsl:otherwise>
  200. </xsl:choose>
  201. <xsl:choose>
  202. <xsl:when test="./*[local-name() = 'originalEncodingName']">
  203. <xsl:apply-templates select="*[local-name() = 'originalEncodingName']"/>
  204. </xsl:when>
  205. <xsl:otherwise>
  206. <xsl:element name="originalEncodingName">utf8</xsl:element>
  207. </xsl:otherwise>
  208. </xsl:choose>
  209. <!--non-properties-->
  210. <xsl:apply-templates select="*[local-name() = 'templates']"/>
  211. <xsl:apply-templates select="*[local-name() = 'property']"/>
  212. </xsl:element>
  213. </xsl:otherwise>
  214. </xsl:choose>
  215. </xsl:template>
  216. </xsl:stylesheet>