xform_1to2.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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 1-->
  10. <!--XSL Transformation from a schema v1 model to a valid BMT schema v2 model-->
  11. <xsl:stylesheet xmlns="http://www.developer.cognos.com/schemas/bmt/2/0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bmtcr1="http://www.developer.cognos.com/schemas/bmt/01" exclude-result-prefixes="bmtcr1">
  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 v2 model-->
  16. <xsl:if test="/bmtcr1:project/@xsi:schemaLocation = 'http://www.developer.cognos.com/schemas/bmt/2/0 BMTModelSpecification.xsd'">
  17. <xsl:message terminate="yes">The input file for this transformer must be a schema v1 model. You tried to use a schema v2 model. Exiting...</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:choose>
  26. <!--Check if the value is group, which is now called folder-->
  27. <xsl:when test=". = 'group'">
  28. <xsl:attribute name="{name(.)}"><xsl:value-of select="'folder'"/></xsl:attribute>
  29. </xsl:when>
  30. <xsl:otherwise>
  31. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  32. </xsl:otherwise>
  33. </xsl:choose>
  34. </xsl:for-each>
  35. <xsl:apply-templates/>
  36. </xsl:element>
  37. </xsl:template>
  38. <!--rename workspace to project, create some new mandatory elements for the schema v2, change the schema validator to the v2 version-->
  39. <xsl:template match="bmtcr1:workspace">
  40. <xsl:element name="project" namespace="http://www.developer.cognos.com/schemas/bmt/2/0">
  41. <xsl:for-each select="@*">
  42. <xsl:choose>
  43. <!--Check if the value is group, which is now called folder-->
  44. <xsl:when test=". = 'group'">
  45. <xsl:attribute name="{name(.)}"><xsl:value-of select="'folder'"/></xsl:attribute>
  46. </xsl:when>
  47. <!--change schema from v1 to v2-->
  48. <xsl:when test="name(.) = 'xsi:schemaLocation'">
  49. <xsl:attribute name="{name(.)}"><xsl:value-of select="'http://www.developer.cognos.com/schemas/bmt/2/0 BMTModelSpecification.xsd'"/></xsl:attribute>
  50. </xsl:when>
  51. <xsl:otherwise>
  52. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  53. </xsl:otherwise>
  54. </xsl:choose>
  55. </xsl:for-each>
  56. <!--re-order the sub-elements-->
  57. <!--name goes in the front-->
  58. <xsl:apply-templates select="bmtcr1:name"/>
  59. <!--create some new mandatory elements for the schema v2-->
  60. <!--it should always be english (en_US)-->
  61. <xsl:element name="languages">
  62. <xsl:element name="language">
  63. <xsl:value-of select="'en_US'"/>
  64. </xsl:element>
  65. </xsl:element>
  66. <!--it should always be english (en_US)-->
  67. <xsl:element name="defaultLanguage">
  68. <xsl:value-of select="'en_US'"/>
  69. </xsl:element>
  70. <xsl:element name="templates"/>
  71. <!--process the rest of the elements from the schema v1-->
  72. <xsl:apply-templates select="bmtcr1:logicalModel"/>
  73. <!--create parameterMaps and securityViews-->
  74. <xsl:element name="parameterMaps"/>
  75. <xsl:element name="securityViews"/>
  76. <!--use the old name-->
  77. <xsl:apply-templates select="bmtcr1:deployments"/>
  78. </xsl:element>
  79. </xsl:template>
  80. <!--remove the language attribute-->
  81. <xsl:template match="bmtcr1:logicalModel">
  82. <xsl:element name="logicalModel">
  83. <xsl:for-each select="@*">
  84. <xsl:choose>
  85. <!--Check if the value is group, which is now called folder-->
  86. <xsl:when test=". = 'group'">
  87. <xsl:attribute name="{name(.)}"><xsl:value-of select="'folder'"/></xsl:attribute>
  88. </xsl:when>
  89. <xsl:otherwise>
  90. <!--skip the language attribute-->
  91. <xsl:if test="not(name(.) = 'language')">
  92. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  93. </xsl:if>
  94. </xsl:otherwise>
  95. </xsl:choose>
  96. </xsl:for-each>
  97. <xsl:apply-templates/>
  98. </xsl:element>
  99. </xsl:template>
  100. <!--rename group to folder-->
  101. <xsl:template match="bmtcr1:group">
  102. <xsl:element name="folder">
  103. <xsl:for-each select="@*">
  104. <xsl:choose>
  105. <!--Check if the value is group, which is now called folder-->
  106. <xsl:when test=". = 'group'">
  107. <xsl:attribute name="{name(.)}"><xsl:value-of select="'folder'"/></xsl:attribute>
  108. </xsl:when>
  109. <xsl:otherwise>
  110. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  111. </xsl:otherwise>
  112. </xsl:choose>
  113. </xsl:for-each>
  114. <xsl:apply-templates/>
  115. </xsl:element>
  116. </xsl:template>
  117. <!--rename queryObject to querySubject-->
  118. <xsl:template match="bmtcr1:queryObject">
  119. <xsl:element name="querySubject">
  120. <xsl:for-each select="@*">
  121. <xsl:choose>
  122. <!--Check if the value is queryObject, which is now called querySubject-->
  123. <xsl:when test=". = 'queryObject'">
  124. <xsl:attribute name="{name(.)}"><xsl:value-of select="'querySubject'"/></xsl:attribute>
  125. </xsl:when>
  126. <xsl:otherwise>
  127. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  128. </xsl:otherwise>
  129. </xsl:choose>
  130. </xsl:for-each>
  131. <xsl:apply-templates/>
  132. </xsl:element>
  133. </xsl:template>
  134. <!--removing the element "type" from a queryObject-->
  135. <xsl:template match="bmtcr1:type">
  136. <xsl:if test="not(name(parent::*) = 'queryObject')">
  137. <xsl:element name="{name(.)}">
  138. <xsl:apply-templates/>
  139. </xsl:element>
  140. </xsl:if>
  141. </xsl:template>
  142. <!--rename queryElement to queryItem-->
  143. <xsl:template match="bmtcr1:queryElement">
  144. <xsl:element name="queryItem">
  145. <xsl:for-each select="@*">
  146. <xsl:choose>
  147. <!--Check if the value is queryElement, which is now called queryItem-->
  148. <xsl:when test=". = 'queryElement'">
  149. <xsl:attribute name="{name(.)}"><xsl:value-of select="'queryItem'"/></xsl:attribute>
  150. </xsl:when>
  151. <xsl:otherwise>
  152. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  153. </xsl:otherwise>
  154. </xsl:choose>
  155. </xsl:for-each>
  156. <!--remove language and characterSet and modify expression-->
  157. <xsl:for-each select="*">
  158. <xsl:if test="not(name(.) = 'language') and not(name(.) = 'characterSet') and not(name(.) = 'expression')">
  159. <xsl:element name="{name(.)}">
  160. <xsl:apply-templates/>
  161. </xsl:element>
  162. </xsl:if>
  163. <!--sub-class expression into calculation-->
  164. <xsl:if test="name(.) = 'expression'">
  165. <xsl:element name="calculation">
  166. <xsl:element name="name"/>
  167. <xsl:element name="expression">
  168. <xsl:apply-templates/>
  169. </xsl:element>
  170. </xsl:element>
  171. </xsl:if>
  172. </xsl:for-each>
  173. </xsl:element>
  174. </xsl:template>
  175. <!--removing the columns element from a sql, but keep the column sub-elements-->
  176. <xsl:template match="bmtcr1:columns">
  177. <xsl:choose>
  178. <xsl:when test="not(name(parent::*) = 'sql')">
  179. <xsl:element name="{name(.)}">
  180. <xsl:apply-templates/>
  181. </xsl:element>
  182. </xsl:when>
  183. <xsl:otherwise>
  184. <xsl:apply-templates/>
  185. </xsl:otherwise>
  186. </xsl:choose>
  187. </xsl:template>
  188. <!--removing the tables element from a sql, but keep the table sub-elements-->
  189. <xsl:template match="bmtcr1:tables">
  190. <xsl:choose>
  191. <xsl:when test="not(name(parent::*) = 'sql')">
  192. <xsl:element name="{name(.)}">
  193. <xsl:apply-templates/>
  194. </xsl:element>
  195. </xsl:when>
  196. <xsl:otherwise>
  197. <xsl:apply-templates/>
  198. </xsl:otherwise>
  199. </xsl:choose>
  200. </xsl:template>
  201. <!--if a dbQuery is found, that has a sibling modelQuery, then eat the dbQuery-->
  202. <xsl:template match="bmtcr1:dbQuery">
  203. <xsl:choose>
  204. <xsl:when test="../bmtcr1:modelQuery">
  205. <!--do nothing-->
  206. </xsl:when>
  207. <xsl:otherwise>
  208. <xsl:element name="dbQuery">
  209. <xsl:for-each select="@*">
  210. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  211. </xsl:for-each>
  212. <xsl:apply-templates/>
  213. </xsl:element>
  214. </xsl:otherwise>
  215. </xsl:choose>
  216. </xsl:template>
  217. <!--modify modelQuery so that it doesn't need a dbQuery sibling anymore-->
  218. <xsl:template match="bmtcr1:modelQuery">
  219. <xsl:element name="modelQuery">
  220. <xsl:for-each select="@*">
  221. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  222. </xsl:for-each>
  223. <xsl:for-each select="../bmtcr1:dbQuery/bmtcr1:source">
  224. <xsl:element name="source">
  225. <xsl:apply-templates/>
  226. </xsl:element>
  227. </xsl:for-each>
  228. <xsl:element name="sql">
  229. <xsl:for-each select="../bmtcr1:dbQuery/bmtcr1:sql">
  230. <xsl:for-each select="@*">
  231. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  232. </xsl:for-each>
  233. <xsl:apply-templates/>
  234. </xsl:for-each>
  235. </xsl:element>
  236. <xsl:apply-templates/>
  237. <xsl:element name="filters"/>
  238. </xsl:element>
  239. </xsl:template>
  240. <!--rename queryElements_collection to queryItems_collection-->
  241. <xsl:template match="bmtcr1:queryElements">
  242. <xsl:element name="queryItems">
  243. <xsl:for-each select="@*">
  244. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  245. </xsl:for-each>
  246. <xsl:apply-templates/>
  247. </xsl:element>
  248. </xsl:template>
  249. <!--rename queryElements_collection to queryItems_collection-->
  250. <xsl:template match="bmtcr1:queryElements_collection">
  251. <xsl:element name="queryItems_collection">
  252. <xsl:for-each select="@*">
  253. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  254. </xsl:for-each>
  255. <xsl:apply-templates/>
  256. </xsl:element>
  257. </xsl:template>
  258. <!--rename association to relationship-->
  259. <xsl:template match="bmtcr1:association">
  260. <xsl:element name="relationship">
  261. <xsl:for-each select="@*">
  262. <xsl:choose>
  263. <!--Check if the value is association, which is now called relationship-->
  264. <xsl:when test=". = 'association'">
  265. <xsl:attribute name="{name(.)}"><xsl:value-of select="'relationship'"/></xsl:attribute>
  266. </xsl:when>
  267. <xsl:otherwise>
  268. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  269. </xsl:otherwise>
  270. </xsl:choose>
  271. </xsl:for-each>
  272. <xsl:apply-templates/>
  273. </xsl:element>
  274. </xsl:template>
  275. <!--rename associationschortcut to relationshipshortcut-->
  276. <xsl:template match="bmtcr1:associationschortcut ">
  277. <xsl:element name="relationshipshortcut">
  278. <xsl:for-each select="@*">
  279. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  280. </xsl:for-each>
  281. <xsl:apply-templates/>
  282. </xsl:element>
  283. </xsl:template>
  284. <!--rename deployments to packages-->
  285. <xsl:template match="bmtcr1:deployments">
  286. <xsl:element name="packages">
  287. <xsl:for-each select="@*">
  288. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  289. </xsl:for-each>
  290. <xsl:apply-templates/>
  291. </xsl:element>
  292. </xsl:template>
  293. <!--rename deployment to package-->
  294. <xsl:template match="bmtcr1:deployment">
  295. <xsl:element name="package">
  296. <xsl:for-each select="@*">
  297. <xsl:choose>
  298. <!--Check if the value is group, which is now called folder-->
  299. <xsl:when test=". = 'group'">
  300. <xsl:attribute name="{name(.)}"><xsl:value-of select="'folder'"/></xsl:attribute>
  301. </xsl:when>
  302. <xsl:otherwise>
  303. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  304. </xsl:otherwise>
  305. </xsl:choose>
  306. </xsl:for-each>
  307. <xsl:apply-templates/>
  308. </xsl:element>
  309. </xsl:template>
  310. <!--rename language="en" to language="en_US" for a "name" element-->
  311. <xsl:template match="bmtcr1:name">
  312. <xsl:element name="name">
  313. <xsl:for-each select="@*">
  314. <xsl:choose>
  315. <!--Check if the value is en, which is now called en_US-->
  316. <xsl:when test=". = 'en'">
  317. <xsl:attribute name="{name(.)}"><xsl:value-of select="'en_US'"/></xsl:attribute>
  318. </xsl:when>
  319. <xsl:otherwise>
  320. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  321. </xsl:otherwise>
  322. </xsl:choose>
  323. </xsl:for-each>
  324. <xsl:apply-templates/>
  325. </xsl:element>
  326. </xsl:template>
  327. </xsl:stylesheet>