ANSUpgrade.xsl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: ans
  5. (C) Copyright IBM Corp. 2005, 2010
  6. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. -->
  8. <!--
  9. * Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  10. * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  11. *
  12. *
  13. *
  14. * This stylesheet generates a most update Analysis High Level Specification (HLS)
  15. * from a beta version.
  16. *
  17. -->
  18. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times" xmlns:exsl="http://exslt.org/common" xmlns:xalan="http://xml.apache.org/xalan" xmlns:java="http://xml.apache.org/xalan/java" extension-element-prefixes="xalan date exsl" exclude-result-prefixes="xalan java date exsl">
  19. <xsl:output method="xml" version="1.0" encoding="UTF-8" omit-xml-declaration="yes"/>
  20. <!--global variables-->
  21. <xsl:variable name="schema0.1" select="number(0.1)"/>
  22. <xsl:variable name="schema0.101" select="number(0.101)"/>
  23. <xsl:variable name="schema0.102" select="number(0.102)"/>
  24. <xsl:variable name="schema0.103" select="number(0.103)"/>
  25. <xsl:variable name="schema0.104" select="number(0.104)"/>
  26. <xsl:variable name="schema0.105" select="number(0.105)"/>
  27. <xsl:variable name="schema0.106" select="number(0.106)"/>
  28. <xsl:variable name="schema0.107" select="number(0.107)"/>
  29. <xsl:variable name="schema0.108" select="number(0.108)"/>
  30. <xsl:variable name="schema0.109" select="number(0.109)"/>
  31. <xsl:variable name="schema1.0" select="number(1.0)"/>
  32. <xsl:variable name="schema1.1" select="number(1.1)"/>
  33. <xsl:variable name="currentSchema" select="number(1.1)"/>
  34. <xsl:variable name="reportSchema">
  35. <xsl:value-of select="number(//analysisReport/attribute::schemaVersion)"/>
  36. </xsl:variable>
  37. <xsl:template match="/PersistHLS">
  38. <!-- Once a point of time we had PersistHLS as the fake root.
  39. New report should have analysisReport as the root.
  40. Here we make sure the fake root is removed during upgrade-->
  41. <xsl:apply-templates select="analysisReport"/>
  42. </xsl:template>
  43. <xsl:template match="analysisReport">
  44. <xsl:choose>
  45. <xsl:when test="$reportSchema &lt; $currentSchema">
  46. <xsl:element name="analysisReport">
  47. <xsl:copy-of select="@*"/>
  48. <xsl:attribute name="schemaVersion"><xsl:value-of select="$currentSchema"/></xsl:attribute>
  49. <xsl:comment>upgrade from version
  50. <xsl:value-of select="$reportSchema"/>
  51. </xsl:comment>
  52. <xsl:if test="not(subtotalEnablementOptions)">
  53. <!--
  54. Prior to 0.106 we did not have subtotalEnablementOptions. The default behavior for remainderMode was
  55. subtract as opposed to null. The default behavior for filterExcludedEnabled was true as opposed to false.
  56. -->
  57. <xsl:element name="subtotalEnablementOptions">
  58. <xsl:attribute name="filterExcludedEnabled">true</xsl:attribute>
  59. <xsl:attribute name="filterIncludedEnabled">true</xsl:attribute>
  60. <xsl:attribute name="remainderEnabled">true</xsl:attribute>
  61. <xsl:attribute name="subtotalVisibleEnabled">false</xsl:attribute>
  62. <xsl:attribute name="summaryEnabled">true</xsl:attribute>
  63. <xsl:attribute name="visibleMembersEnabled">true</xsl:attribute>
  64. <xsl:attribute name="remainderMode">subtract</xsl:attribute>
  65. </xsl:element>
  66. </xsl:if>
  67. <!--
  68. Convert the 8.1 suppression to work order 2567 suppression. Test for each variant separately
  69. -->
  70. <xsl:if test="filterSet/zeroSuppress">
  71. <xsl:if test="not(otherOptions)">
  72. <xsl:element name="otherOptions">
  73. <xsl:attribute name="treatZerosAsNullsForSuppression">true</xsl:attribute>
  74. <xsl:attribute name="suppressionState"><xsl:value-of select="/analysisReport/filterSet/zeroSuppress/@state"/></xsl:attribute>
  75. </xsl:element>
  76. </xsl:if>
  77. <xsl:apply-templates>
  78. <xsl:with-param name="suppressionStateName">suppressionState</xsl:with-param>
  79. <xsl:with-param name="suppressionStateValue" select="/analysisReport/filterSet/zeroSuppress/@state"/>
  80. <xsl:with-param name="treatmentName">treatZerosAsNullsForSuppression</xsl:with-param>
  81. <xsl:with-param name="treatmentValue">true</xsl:with-param>
  82. </xsl:apply-templates>
  83. </xsl:if>
  84. <xsl:if test="(filterSet/nullSuppress) and not (filterSet/zeroSuppress)">
  85. <xsl:if test="not(otherOptions)">
  86. <xsl:element name="otherOptions">
  87. <xsl:attribute name="treatZerosAsNullsForSuppression">false</xsl:attribute>
  88. <xsl:attribute name="suppressionState"><xsl:value-of select="/analysisReport/filterSet/nullSuppress/@state"/></xsl:attribute>
  89. </xsl:element>
  90. </xsl:if>
  91. <xsl:apply-templates>
  92. <xsl:with-param name="suppressionStateName">suppressionState</xsl:with-param>
  93. <xsl:with-param name="suppressionStateValue" select="/analysisReport/filterSet/nullSuppress/@state"/>
  94. <xsl:with-param name="treatmentName">treatZerosAsNullsForSuppression</xsl:with-param>
  95. <xsl:with-param name="treatmentValue">true</xsl:with-param>
  96. </xsl:apply-templates>
  97. </xsl:if>
  98. <xsl:if test="not(filterSet/nullSuppress) and not (filterSet/zeroSuppress)">
  99. <xsl:choose>
  100. <xsl:when test="not(otherOptions)">
  101. <xsl:apply-templates/>
  102. </xsl:when>
  103. <xsl:otherwise>
  104. <xsl:apply-templates>
  105. <xsl:with-param name="treatmentName">treatZerosAsNullsForSuppression</xsl:with-param>
  106. <xsl:with-param name="treatmentValue" select="/analysisReport/otherOptions/@treatZerosAsNullForSparsityRemoval"/>
  107. <xsl:with-param name="suppressionStateName">suppressionState</xsl:with-param>
  108. <xsl:with-param name="suppressionStateValue">none</xsl:with-param>
  109. </xsl:apply-templates>
  110. </xsl:otherwise>
  111. </xsl:choose>
  112. </xsl:if>
  113. </xsl:element>
  114. </xsl:when>
  115. <xsl:otherwise>
  116. <xsl:copy-of select="."/>
  117. </xsl:otherwise>
  118. </xsl:choose>
  119. </xsl:template>
  120. <xsl:template match="otherOptions">
  121. <xsl:param name="suppressionStateName"/>
  122. <xsl:param name="suppressionStateValue"/>
  123. <xsl:param name="treatmentName"/>
  124. <xsl:param name="treatmentValue"/>
  125. <xsl:element name="otherOptions">
  126. <xsl:choose>
  127. <xsl:when test="@treatZerosAsNullsForSparsityRemoval">
  128. <xsl:attribute name="{$suppressionStateName}"><xsl:value-of select="$suppressionStateValue"/></xsl:attribute>
  129. <xsl:attribute name="treatZerosAsNullsForSuppression"><xsl:value-of select="@treatZerosAsNullsForSparsityRemoval"/></xsl:attribute>
  130. </xsl:when>
  131. <xsl:otherwise>
  132. <xsl:attribute name="{$suppressionStateName}"><xsl:value-of select="$suppressionStateValue"/></xsl:attribute>
  133. <xsl:attribute name="{$treatmentName}"><xsl:value-of select="$treatmentValue"/></xsl:attribute>
  134. </xsl:otherwise>
  135. </xsl:choose>
  136. </xsl:element>
  137. </xsl:template>
  138. <!--remove old zero and null suppress. should be upgraded by this point.-->
  139. <xsl:template match="filterSet/zeroSuppress">
  140. </xsl:template>
  141. <xsl:template match="filterSet/nullSuppress">
  142. </xsl:template>
  143. <xsl:template match="subtotalEnablementOptions">
  144. <xsl:element name="subtotalEnablementOptions">
  145. <xsl:if test="not(@remainderMode) or not(@remaindermode)">
  146. <xsl:attribute name="remainderMode">subtract</xsl:attribute>
  147. </xsl:if>
  148. <xsl:apply-templates select="@*"/>
  149. </xsl:element>
  150. </xsl:template>
  151. <xsl:template match="measureSortSpec|topBottomFilter">
  152. <xsl:element name="{name()}">
  153. <xsl:copy-of select="@*"/>
  154. <xsl:choose>
  155. <xsl:when test="$reportSchema &lt; $schema0.101">
  156. <xsl:variable name="v_locked">
  157. <xsl:value-of select="ancestor::*/properties/@locked"/>
  158. </xsl:variable>
  159. <xsl:element name="scope">
  160. <xsl:choose>
  161. <xsl:when test="context">
  162. <xsl:element name="memberExprs">
  163. <xsl:copy-of select="context/*"/>
  164. </xsl:element>
  165. </xsl:when>
  166. <xsl:otherwise>
  167. <!-- add <defaultMemberContext> for not locked block -->
  168. <xsl:if test="$v_locked != 'true'">
  169. <xsl:element name="memberExprs">
  170. <xsl:element name="defaultMemberContext"/>
  171. </xsl:element>
  172. </xsl:if>
  173. </xsl:otherwise>
  174. </xsl:choose>
  175. <xsl:choose>
  176. <xsl:when test="measure">
  177. <xsl:element name="measureExpr">
  178. <xsl:copy-of select="measure"/>
  179. </xsl:element>
  180. </xsl:when>
  181. <xsl:when test="calcRef">
  182. <xsl:element name="measureExpr">
  183. <xsl:copy-of select="calcRef"/>
  184. </xsl:element>
  185. </xsl:when>
  186. <xsl:otherwise>
  187. <xsl:element name="measureExpr">
  188. <xsl:element name="measure">default</xsl:element>
  189. </xsl:element>
  190. </xsl:otherwise>
  191. </xsl:choose>
  192. </xsl:element>
  193. </xsl:when>
  194. <xsl:otherwise>
  195. <xsl:apply-templates/>
  196. </xsl:otherwise>
  197. </xsl:choose>
  198. </xsl:element>
  199. </xsl:template>
  200. <xsl:template match="scope">
  201. <xsl:variable name="v_locked">
  202. <xsl:value-of select="ancestor::*/properties/@locked"/>
  203. </xsl:variable>
  204. <!-- For analysis before 0.104, we didn't distinguish empty and default member context.
  205. So we need to upgrade those analysis to use default context for any non-locked block. From 0.104, we
  206. will write out <defaultMemberContext> for default context and empty for empty context. -->
  207. <xsl:choose>
  208. <xsl:when test="$v_locked != 'true' and $reportSchema &lt; $schema0.104">
  209. <xsl:element name="{name()}">
  210. <xsl:copy-of select="@*"/>
  211. <xsl:if test="not(memberExprs)">
  212. <xsl:element name="memberExprs">
  213. <xsl:element name="defaultMemberContext"/>
  214. </xsl:element>
  215. </xsl:if>
  216. <xsl:apply-templates/>
  217. </xsl:element>
  218. </xsl:when>
  219. <xsl:otherwise>
  220. <xsl:copy-of select="."/>
  221. </xsl:otherwise>
  222. </xsl:choose>
  223. </xsl:template>
  224. <xsl:template match="scatterchartoptions">
  225. <!-- Scatter charts are no longer supported. -->
  226. </xsl:template>
  227. <xsl:template match="childrenOfMeasureBlock/hiddenItems/members">
  228. <!-- change <members> to <measures>, and <member> to <measure> -->
  229. <xsl:element name="measures">
  230. <xsl:for-each select="./member">
  231. <xsl:element name="measure">
  232. <xsl:value-of select="."/>
  233. </xsl:element>
  234. </xsl:for-each>
  235. </xsl:element>
  236. </xsl:template>
  237. <xsl:template match="attributes/members">
  238. <!-- Change <attributes><members><member> to <attributes><attribute> -->
  239. <xsl:for-each select="./member">
  240. <xsl:element name="attribute">
  241. <xsl:value-of select="."/>
  242. </xsl:element>
  243. </xsl:for-each>
  244. </xsl:template>
  245. <xsl:template match="ci[@type='context']">
  246. <!-- we should remove any default context for locked block -->
  247. <xsl:variable name="v_locked">
  248. <xsl:value-of select="ancestor::*/properties/@locked"/>
  249. </xsl:variable>
  250. <xsl:variable name="v_value" select="."/>
  251. <xsl:if test="$v_locked != 'true' or $v_value != 'default'">
  252. <xsl:copy-of select="."/>
  253. </xsl:if>
  254. </xsl:template>
  255. <xsl:template match="childrenOfBlock|childrenOfMeasureBlock|depthBlock|nestedBlock|levelBlock|namedSetBlock|v5Block|memberBlock">
  256. <xsl:element name="{name()}">
  257. <xsl:copy-of select="@*"/>
  258. <xsl:if test="name() != 'memberBlock'">
  259. <xsl:if test="not(properties)">
  260. <xsl:element name="properties">
  261. <xsl:attribute name="remainderMode">subtract</xsl:attribute>
  262. </xsl:element>
  263. </xsl:if>
  264. </xsl:if>
  265. <xsl:if test="name() != 'childrenOfMeasureBlock'">
  266. <xsl:if test="not(subtotals)">
  267. <xsl:element name="subtotals">
  268. <xsl:attribute name="excluded">true</xsl:attribute>
  269. </xsl:element>
  270. </xsl:if>
  271. </xsl:if>
  272. <xsl:apply-templates/>
  273. </xsl:element>
  274. </xsl:template>
  275. <xsl:template match="childrenOfBlock/properties|childrenOfMeasureBlock/properties|depthBlock/properties|nestedBlock/properties|levelBlock/properties|namedSetBlock/properties|v5Block/properties">
  276. <xsl:element name="{name()}">
  277. <xsl:if test="not(@remainderMode) or not(@remaindermode)">
  278. <xsl:attribute name="remainderMode">subtract</xsl:attribute>
  279. </xsl:if>
  280. <xsl:apply-templates select="@*"/>
  281. </xsl:element>
  282. </xsl:template>
  283. <xsl:template match="childrenOfBlock/subtotals|memberBlock/subtotals|depthBlock/subtotals|nestedBlock/subtotals|levelBlock/subtotals|namedSetBlock/subtotals|v5Block/subtotals">
  284. <xsl:element name="{name()}">
  285. <xsl:if test="not(@excluded)">
  286. <xsl:attribute name="excluded">true</xsl:attribute>
  287. </xsl:if>
  288. <xsl:apply-templates select="@*"/>
  289. </xsl:element>
  290. </xsl:template>
  291. <xsl:template match="reportOptions/pageBreaks">
  292. <xsl:variable name="section" select="./@*[name() = 'section']"/>
  293. <xsl:element name="{name()}">
  294. <xsl:for-each select="@*">
  295. <xsl:if test="name() != 'section'">
  296. <xsl:copy-of select="."/>
  297. </xsl:if>
  298. </xsl:for-each>
  299. <xsl:if test="$section">
  300. <xsl:element name="sectionFilterId">
  301. <xsl:attribute name="value"><xsl:choose><xsl:when test="starts-with($section, 'uuid:')"><xsl:value-of select="concat('x', substring($section, 6))"/></xsl:when><xsl:otherwise><xsl:value-of select="$section"/></xsl:otherwise></xsl:choose></xsl:attribute>
  302. </xsl:element>
  303. </xsl:if>
  304. <xsl:apply-templates/>
  305. </xsl:element>
  306. </xsl:template>
  307. <!--
  308. Old reports (< 0.109) did not have an axisExpr element between the rows|columns
  309. element and the expression elements. In that case we need to add an
  310. axisExpr element.
  311. The original upgrade (0.109 - 1.0) rule did NOT check to see if we already had an
  312. axisExpr element so subsequent upgrades added superflous axisExpr
  313. elements. If see those we have to skip/delete them.
  314. NOTE: THE ORDER OF THESE TEMPLATES IS IMPORTANT.
  315. -->
  316. <xsl:template match="dataMatrix/rows/axisExpr|dataMatrix/columns/axisExpr">
  317. <xsl:choose>
  318. <xsl:when test="axisExpr">
  319. <!-- Yikes we have nested axisExprs. Ignore the nested one and process it's children. -->
  320. <xsl:apply-templates/>
  321. </xsl:when>
  322. <xsl:otherwise>
  323. <xsl:element name="axisExpr">
  324. <xsl:apply-templates/>
  325. </xsl:element>
  326. </xsl:otherwise>
  327. </xsl:choose>
  328. </xsl:template>
  329. <xsl:template match="dataMatrix/rows|dataMatrix/columns">
  330. <!-- We need to add an axisExpr -->
  331. <xsl:element name="{name()}">
  332. <xsl:choose>
  333. <xsl:when test="not(axisExpr)">
  334. <xsl:element name="axisExpr">
  335. <xsl:apply-templates/>
  336. </xsl:element>
  337. </xsl:when>
  338. <xsl:otherwise>
  339. <xsl:apply-templates/>
  340. </xsl:otherwise>
  341. </xsl:choose>
  342. </xsl:element>
  343. </xsl:template>
  344. <!--
  345. Interim upgrade from 0.103-0.106
  346. We want attributes to be consistently named, capitalized, etc
  347. -->
  348. <xsl:template match="subtotalEnablementOptions/@filterexcludedenabled">
  349. <xsl:attribute name="filterExcludedEnabled"><xsl:value-of select="../@filterexcludedenabled"/></xsl:attribute>
  350. </xsl:template>
  351. <xsl:template match="subtotalEnablementOptions/@filterincludedenabled">
  352. <xsl:attribute name="filterIncludedEnabled"><xsl:value-of select="../@filterincludedenabled"/></xsl:attribute>
  353. </xsl:template>
  354. <xsl:template match="subtotalEnablementOptions/@remainderenabled">
  355. <xsl:attribute name="remainderEnabled"><xsl:value-of select="../@remainderenabled"/></xsl:attribute>
  356. </xsl:template>
  357. <xsl:template match="subtotalEnablementOptions/@subtotalvisibleenabled">
  358. <xsl:attribute name="subtotalVisibleEnabled"><xsl:value-of select="../@subtotalvisibleenabled"/></xsl:attribute>
  359. </xsl:template>
  360. <xsl:template match="subtotalEnablementOptions/@summaryenabled">
  361. <xsl:attribute name="summaryEnabled"><xsl:value-of select="../@summaryenabled"/></xsl:attribute>
  362. </xsl:template>
  363. <xsl:template match="subtotalEnablementOptions/@visiblemembersenabled">
  364. <xsl:attribute name="visibleMembersEnabled"><xsl:value-of select="../@visiblemembersenabled"/></xsl:attribute>
  365. </xsl:template>
  366. <xsl:template match="subtotalEnablementOptions/@remaindermode">
  367. <xsl:attribute name="remainderMode"><xsl:value-of select="../@remaindermode"/></xsl:attribute>
  368. </xsl:template>
  369. <xsl:template match="properties/@remaindermode">
  370. <xsl:attribute name="remainderMode"><xsl:value-of select="../@remaindermode"/></xsl:attribute>
  371. </xsl:template>
  372. <!-- Copy anything that is unmatched over to output. -->
  373. <xsl:template match="@*|node()">
  374. <xsl:copy>
  375. <xsl:apply-templates select="@*|node()"/>
  376. </xsl:copy>
  377. </xsl:template>
  378. </xsl:stylesheet>