RSUpgradeReport.xsl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: rspecupgrade
  5. (C) Copyright IBM Corp. 2005, 2010
  6. US Government Users Restricted Rights - Use, duplication or disclosure
  7. restricted by GSA ADP Schedule Contract with IBM Corp.
  8. -->
  9. <!-- COPYRIGHT_DATA { 'YEAR':[2005, 2009], 'RELEASE':['colorado_wave1'], 'VISIBLE':'YES', 'COMPONENT':'rspecupgrade' }-->
  10. <!--All lines above the COPYRIGHT_DATA line will be replaced when copyright notices are generated. -->
  11. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:baltic="http://developer.cognos.com/schemas/report/1/" xmlns="http://developer.cognos.com/schemas/report/2.0/" 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" xmlns:qfw="java:com.qfw.V4toV5.V4toV5QuerySet" extension-element-prefixes="xalan java date exsl qfw" exclude-result-prefixes="xalan java baltic date exsl qfw">
  12. <xsl:template match="baltic:report">
  13. <xsl:if test="$var_transformationTimeStamp != ''">
  14. <xsl:comment>
  15. <xsl:copy-of select="$var_transformationTimeStamp"/>
  16. </xsl:comment>
  17. </xsl:if>
  18. <report>
  19. <!--
  20. <xsl:attribute name="expressionLocale"><xsl:value-of select="@lang"/></xsl:attribute>
  21. Does not seem to work when using a DOM document as source. So we use the for-each below.
  22. -->
  23. <xsl:for-each select="@*">
  24. <xsl:if test="name(.) = 'xml:lang'">
  25. <xsl:attribute name="expressionLocale"><xsl:value-of select="."/></xsl:attribute>
  26. </xsl:if>
  27. </xsl:for-each>
  28. <!-- WO1174 - Baltic Report Styles in Bering -->
  29. <xsl:attribute name="useStyleVersion"><xsl:value-of select="1"/></xsl:attribute>
  30. <!-- Trakker 531850.2. Set interactivePageBreakByFrame attribute to true to maintain Baltic behavior. -->
  31. <xsl:attribute name="interactivePageBreakByFrame">true</xsl:attribute>
  32. <xsl:if test="$var_modelConnection != ''">
  33. <modelPath>
  34. <xsl:value-of select="$var_modelConnection"/>
  35. </modelPath>
  36. </xsl:if>
  37. <!--
  38. If the upgraded queries element is not empty,
  39. Copy the upgraded queries.
  40. Modify queries by adding new data items
  41. for each level header and footer.
  42. -->
  43. <xsl:choose>
  44. <xsl:when test="/baltic:report/ret">
  45. <xsl:if test="count( /baltic:report/ret/node()[local-name()='queries']/node()[local-name()='query'] ) &gt; 0">
  46. <xsl:apply-templates select="/baltic:report/ret/node()[local-name()='queries']" mode="q">
  47. <xsl:with-param name="p_report" select="."/>
  48. </xsl:apply-templates>
  49. </xsl:if>
  50. </xsl:when>
  51. <xsl:otherwise>
  52. <xsl:if test="count( //*[local-name()='queries']/node()[local-name()='query'] ) &gt; 0">
  53. <xsl:apply-templates select="//*[local-name()='queries']" mode="q">
  54. <xsl:with-param name="p_report" select="."/>
  55. </xsl:apply-templates>
  56. </xsl:if>
  57. </xsl:otherwise>
  58. </xsl:choose>
  59. <xsl:apply-templates select="baltic:layoutList"/>
  60. <xsl:apply-templates select="baltic:variableList"/>
  61. <xsl:apply-templates select="baltic:burst"/>
  62. <xsl:if test="count(baltic:XMLAttribute) &gt; 0">
  63. <xsl:variable name="var_XMLAttributes">
  64. <xsl:apply-templates select="baltic:XMLAttribute"/>
  65. </xsl:variable>
  66. <XMLAttributes>
  67. <xsl:copy-of select="$var_XMLAttributes"/>
  68. </XMLAttributes>
  69. </xsl:if>
  70. <!--
  71. upgradeInfo is a Cognos8 element used for reporting errors.
  72. This rule allows the upgradeInfo to be transferred to the Bering specification
  73. for further processing.
  74. -->
  75. <xsl:apply-templates select="baltic:upgradeInfo" mode="upgradeInfo"/>
  76. <!--
  77. Copy over th baltic query section so we can use it during later processing steps.
  78. -->
  79. <xsl:copy-of select="/baltic:report/baltic:querySet"/>
  80. <!-- copy over the QFW upgrade information for use in intermediate stages. It will be removed
  81. during post processing.
  82. -->
  83. <xsl:copy-of select="/baltic:report/ret"/>
  84. </report>
  85. </xsl:template>
  86. <xsl:template match="baltic:modelConnection">
  87. <source>
  88. <model>
  89. <xsl:variable name="v_name" select="/baltic:report/baltic:metadataModel/baltic:value/baltic:item/baltic:searchPath/baltic:value"/>
  90. <xsl:choose>
  91. <xsl:when test="$v_name != ''">
  92. <xsl:value-of select="$v_name"/>
  93. </xsl:when>
  94. <xsl:otherwise>
  95. <xsl:value-of select="@name"/>
  96. </xsl:otherwise>
  97. </xsl:choose>
  98. </model>
  99. </source>
  100. </xsl:template>
  101. <xsl:template name="notImplemented">
  102. <xsl:param name="p_target"/>
  103. <xsl:text>&#10;</xsl:text>
  104. <xsl:comment>
  105. <xsl:text> NOTE: Migration of "</xsl:text>
  106. <xsl:copy-of select="$p_target"/>
  107. <xsl:text>" has not been implemented yet. </xsl:text>
  108. </xsl:comment>
  109. <xsl:text>&#10;</xsl:text>
  110. </xsl:template>
  111. <!-- Copy over the query. If it does not have a detailFilters
  112. * section, and there are some from master/details then add
  113. * a new detailFilters section.
  114. -->
  115. <xsl:template match="*[local-name()='query']" mode="q">
  116. <xsl:param name="p_report"/>
  117. <xsl:element name="query">
  118. <xsl:for-each select="@*">
  119. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  120. </xsl:for-each>
  121. <xsl:apply-templates mode="q">
  122. <xsl:with-param name="p_report">
  123. <xsl:copy-of select="$p_report"/>
  124. </xsl:with-param>
  125. </xsl:apply-templates>
  126. <xsl:if test="count(./node()[local-name()='detailFilters']) = 0">
  127. <xsl:call-template name="generateMasterDetailFilters">
  128. <xsl:with-param name="p_detailQueryName" select="@name"/>
  129. </xsl:call-template>
  130. </xsl:if>
  131. </xsl:element>
  132. </xsl:template>
  133. <!-- Copy over the detailFilters section.
  134. * Add any new filters from master/details.
  135. -->
  136. <xsl:template match="*[local-name()='detailFilters']" mode="q">
  137. <xsl:param name="p_report"/>
  138. <xsl:element name="detailFilters">
  139. <xsl:for-each select="@*">
  140. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  141. </xsl:for-each>
  142. <xsl:apply-templates mode="q">
  143. <xsl:with-param name="p_report">
  144. <xsl:copy-of select="$p_report"/>
  145. </xsl:with-param>
  146. </xsl:apply-templates>
  147. <xsl:call-template name="generateMasterDetailFilter">
  148. <xsl:with-param name="p_detailQueryName" select="../@name"/>
  149. </xsl:call-template>
  150. </xsl:element>
  151. </xsl:template>
  152. <!--
  153. Copy all elements under queries element from the migrated query set.
  154. Copy all attributes as well.
  155. -->
  156. <xsl:template match="*" mode="q">
  157. <xsl:param name="p_report"/>
  158. <xsl:copy>
  159. <xsl:for-each select="@*">
  160. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  161. </xsl:for-each>
  162. <xsl:apply-templates mode="q">
  163. <xsl:with-param name="p_report">
  164. <xsl:copy-of select="$p_report"/>
  165. </xsl:with-param>
  166. </xsl:apply-templates>
  167. </xsl:copy>
  168. </xsl:template>
  169. <!--
  170. Add new data items under selection for each level header and footer.
  171. -->
  172. <xsl:template match="*[local-name()='selection']" mode="q">
  173. <xsl:param name="p_report"/>
  174. <xsl:copy>
  175. <xsl:for-each select="attribute::*">
  176. <xsl:copy/>
  177. </xsl:for-each>
  178. <xsl:apply-templates mode="q"/>
  179. <xsl:call-template name="addItems">
  180. <xsl:with-param name="p_queryName">
  181. <xsl:value-of select="../@name"/>
  182. </xsl:with-param>
  183. <xsl:with-param name="p_report">
  184. <xsl:copy-of select="$p_report"/>
  185. </xsl:with-param>
  186. </xsl:call-template>
  187. </xsl:copy>
  188. </xsl:template>
  189. <xsl:template name="addItems">
  190. <xsl:param name="p_queryName"/>
  191. <xsl:param name="p_report"/>
  192. <!-- Add a new dataItem for each crosstab header or footer that references the specifed query. -->
  193. <!--<xsl:comment>
  194. <xsl:text>Adding H/F dataitems to query: "</xsl:text>
  195. <xsl:value-of select="$p_queryName"/>
  196. <xsl:text>".</xsl:text>
  197. </xsl:comment>-->
  198. <xsl:apply-templates select="$p_report//baltic:crosstab[@refQuery=$p_queryName]//baltic:levelHeader | $p_report//baltic:crosstab[@refQuery=$p_queryName]//baltic:levelFooter" mode="q">
  199. <xsl:with-param name="p_report">
  200. <xsl:copy-of select="$p_report"/>
  201. </xsl:with-param>
  202. </xsl:apply-templates>
  203. <!-- Now do the same for the headers and footers in crosstabs that reference v4 queries that have been mapped to a new v5 query. -->
  204. <xsl:choose>
  205. <xsl:when test="/baltic:report/ret">
  206. <xsl:for-each select="/baltic:report/ret/theMap/node()[local-name()='queryMap' and @equiv=$p_queryName]/@ignored">
  207. <xsl:variable name="v_v4queryName" select="."/>
  208. <!--<xsl:comment>
  209. <xsl:text>Adding H/F dataitems to query: "</xsl:text>
  210. <xsl:value-of select="$p_queryName"/>
  211. <xsl:text>" that come from the V4 BIQuery: "</xsl:text>
  212. <xsl:value-of select="$v_v4queryName"/>
  213. <xsl:text>".</xsl:text>
  214. </xsl:comment>-->
  215. <xsl:apply-templates select="$p_report//baltic:crosstab[@refQuery=$v_v4queryName]//baltic:levelHeader | $p_report//baltic:crosstab[@refQuery=$v_v4queryName]//baltic:levelFooter" mode="q">
  216. <xsl:with-param name="p_report">
  217. <xsl:copy-of select="$p_report"/>
  218. </xsl:with-param>
  219. </xsl:apply-templates>
  220. </xsl:for-each>
  221. </xsl:when>
  222. <xsl:otherwise>
  223. <xsl:for-each select="//*[local-name()='queryMap' and @equiv=$p_queryName]/@ignored">
  224. <xsl:variable name="v_v4queryName" select="."/>
  225. <!--<xsl:comment>
  226. <xsl:text>Adding H/F dataitems to query: "</xsl:text>
  227. <xsl:value-of select="$p_queryName"/>
  228. <xsl:text>" that come from the V4 BIQuery: "</xsl:text>
  229. <xsl:value-of select="$v_v4queryName"/>
  230. <xsl:text>".</xsl:text>
  231. </xsl:comment>-->
  232. <xsl:apply-templates select="$p_report//baltic:crosstab[@refQuery=$v_v4queryName]//baltic:levelHeader | $p_report//baltic:crosstab[@refQuery=$v_v4queryName]//baltic:levelFooter" mode="q">
  233. <xsl:with-param name="p_report">
  234. <xsl:copy-of select="$p_report"/>
  235. </xsl:with-param>
  236. </xsl:apply-templates>
  237. </xsl:for-each>
  238. </xsl:otherwise>
  239. </xsl:choose>
  240. </xsl:template>
  241. <xsl:template match="baltic:levelHeader | baltic:levelFooter" mode="q">
  242. <xsl:param name="p_report"/>
  243. <xsl:variable name="v_name">
  244. <xsl:call-template name="getItemNameFromLevelReference">
  245. <xsl:with-param name="p_queryName" select="ancestor::baltic:crosstab[1]/@refQuery"/>
  246. <xsl:with-param name="p_levelRef" select="../@refLevel"/>
  247. </xsl:call-template>
  248. </xsl:variable>
  249. <dataItem name="aggregate({$v_name})">
  250. <expression>aggregate(currentMeasure within detail [<xsl:value-of select="$v_name"/>])</expression>
  251. </dataItem>
  252. </xsl:template>
  253. <!--
  254. * Return the name of the query that should be used.
  255. * @param refQuery Name of the query that is being looked up.
  256. * @return If the refQuery is being ignored, then return the name of the
  257. * equivelent query. Otherwise return refQuery
  258. -->
  259. <xsl:template name="getQueryTemplate">
  260. <xsl:param name="refQuery"/>
  261. <xsl:variable name="v_refQuery">
  262. <xsl:choose>
  263. <xsl:when test="/baltic:report/ret">
  264. <xsl:value-of select="/baltic:report/ret/theMap/node()[local-name()='queryMap' and @ignored=$refQuery]/@equiv"/>
  265. </xsl:when>
  266. <xsl:otherwise>
  267. <xsl:value-of select="//*[local-name()='queryMap' and @ignored=$refQuery]/@equiv"/>
  268. </xsl:otherwise>
  269. </xsl:choose>
  270. </xsl:variable>
  271. <xsl:choose>
  272. <xsl:when test="$v_refQuery != ''">
  273. <xsl:value-of select="$v_refQuery"/>
  274. </xsl:when>
  275. <xsl:otherwise>
  276. <xsl:value-of select="$refQuery"/>
  277. </xsl:otherwise>
  278. </xsl:choose>
  279. </xsl:template>
  280. <!-- -->
  281. <xsl:template name="getCubeOrCubeReference">
  282. <xsl:param name="p_queryNode" select="."/>
  283. <xsl:choose>
  284. <xsl:when test="$p_queryNode/baltic:cube">
  285. <!--<xsl:comment>Query <xsl:value-of select="$p_queryNode/@name"/> has a cube.</xsl:comment>-->
  286. <xsl:copy-of select="$p_queryNode/baltic:cube"/>
  287. </xsl:when>
  288. <xsl:when test="$p_queryNode/baltic:cubeReference">
  289. <xsl:variable name="v_refQuery" select="$p_queryNode/baltic:cubeReference/@refQuery"/>
  290. <!--<xsl:comment>Query <xsl:value-of select="$p_queryNode/@name"/> has a cubeReference to Query <xsl:value-of select="$v_refQuery"/>.</xsl:comment>-->
  291. <xsl:copy-of select="/baltic:report/baltic:querySet/baltic:BIQuery[@name=$v_refQuery]/baltic:cube"/>
  292. </xsl:when>
  293. <!--<xsl:otherwise>
  294. <xsl:comment>Query <xsl:value-of select="$p_queryNode/@name"/> has no cube or cubeReference.</xsl:comment>
  295. </xsl:otherwise>-->
  296. </xsl:choose>
  297. </xsl:template>
  298. <!-- Retrieve the cube that goes with a query name.
  299. * If the query names uses a cube reference, then the
  300. * derefenced cube is returned.
  301. *
  302. * p_queryName Name of the query to use for looking up
  303. * the cube.
  304. -->
  305. <xsl:template name="getCube">
  306. <xsl:param name="p_queryName"/>
  307. <xsl:call-template name="getCubeOrCubeReference">
  308. <xsl:with-param name="p_queryNode" select="/baltic:report/baltic:querySet/baltic:BIQuery[@name=$p_queryName]"/>
  309. </xsl:call-template>
  310. </xsl:template>
  311. <!-- A hard coded message is returned if the key cannot be found
  312. * Other templates detect this error message and react to it.
  313. -->
  314. <xsl:template name="getKeyItemNameForLevel">
  315. <xsl:param name="p_level" select="."/>
  316. <xsl:variable name="v_itemName">
  317. <xsl:variable name="v_name" select="$p_level/baltic:dataItem[@key='true']/@name"/>
  318. <xsl:variable name="v_alias" select="$p_level/baltic:item[@key='true']/@alias"/>
  319. <xsl:variable name="v_refItem" select="$p_level/baltic:item[@key='true']/@refItem"/>
  320. <xsl:choose>
  321. <xsl:when test="$v_name!=''">
  322. <xsl:value-of select="$v_name"/>
  323. </xsl:when>
  324. <xsl:when test="$v_alias != ''">
  325. <xsl:value-of select="$v_alias"/>
  326. </xsl:when>
  327. <xsl:when test="$v_refItem != ''">
  328. <xsl:value-of select="$v_refItem"/>
  329. </xsl:when>
  330. <xsl:when test="$p_level/baltic:dataItem/@name">
  331. <xsl:value-of select="$p_level/baltic:dataItem/@name"/>
  332. </xsl:when>
  333. <xsl:when test="$p_level/baltic:item/@alias">
  334. <xsl:value-of select="$p_level/baltic:item/@alias"/>
  335. </xsl:when>
  336. <xsl:when test="$p_level/baltic:item/@refItem">
  337. <xsl:value-of select="$p_level/baltic:item/@refItem"/>
  338. </xsl:when>
  339. <xsl:otherwise>
  340. <!-- Do NOT log this as an error. There is code that will accept the error and
  341. * still produce valid reports.
  342. * see test case //rspecupgrade/bering/main/rspecupgrade/testdata/V4QSAccept/masters/V5DebugNormalizedReportSpecs/RSUpgrade_v4_QSAccept_21.xml
  343. *
  344. * See trakker 533492.2 for a gotcha. Levels without data items or items may not run
  345. * correctly in Baltic.
  346. -->
  347. <xsl:value-of select="'ERROR: Cannot find item or dataItem for the level referenced.'"/>
  348. </xsl:otherwise>
  349. </xsl:choose>
  350. </xsl:variable>
  351. <xsl:value-of select="$v_itemName"/>
  352. </xsl:template>
  353. <!-- A hard coded message is returned if the item cannot be found
  354. * Other templates detect this error message and react to it.
  355. * @see getKeyItemNameForLevel
  356. -->
  357. <xsl:template name="getItemNameFromLevelReference">
  358. <xsl:param name="p_queryName"/>
  359. <xsl:param name="p_levelRef"/>
  360. <xsl:variable name="var_cube">
  361. <xsl:call-template name="getCubeOrCubeReference">
  362. <xsl:with-param name="p_queryNode" select="/baltic:report/baltic:querySet/baltic:BIQuery[@name=$p_queryName]"/>
  363. </xsl:call-template>
  364. </xsl:variable>
  365. <xsl:variable name="v_refDataItem">
  366. <xsl:call-template name="getKeyItemNameForLevel">
  367. <xsl:with-param name="p_level" select="$var_cube/baltic:cube/baltic:dimension/baltic:level[@name=$p_levelRef]"/>
  368. </xsl:call-template>
  369. </xsl:variable>
  370. <xsl:value-of select="$v_refDataItem"/>
  371. </xsl:template>
  372. <!-- sortItem is the sortOrder attribute value in the item, or if that is
  373. * not set, then it is the value of the sort attribute in the tabular model.
  374. * At the point this template is being matched we have a doc fragment
  375. * with the item as its root, and we cannot go up to look at the tabular
  376. * model. All the data items will be entered with some sortOrder
  377. * attribute cleaned up in a different pass.
  378. -->
  379. <xsl:template match="baltic:item" mode="generate_sortItems">
  380. <!-- later passes will handle the case where there is no sorting.
  381. * sortOrder being empty signifies that the tabular model is to be examined.
  382. * sortOrder being "none" indicates we have examined the sort order, and no tabular model lookup is needed.
  383. -->
  384. <xsl:variable name="v_itemName">
  385. <xsl:choose>
  386. <xsl:when test="@alias">
  387. <xsl:value-of select="@alias"/>
  388. </xsl:when>
  389. <xsl:otherwise>
  390. <xsl:value-of select="@refItem"/>
  391. </xsl:otherwise>
  392. </xsl:choose>
  393. </xsl:variable>
  394. <sortItem refDataItem="{$v_itemName}" originalRefItem="{@refItem}" sortOrder="{@sort}"/>
  395. </xsl:template>
  396. <!-- Copy over all of the upgradeInfo element -->
  397. <xsl:template match="*" mode="upgradeInfo">
  398. <xsl:element name="{name()}">
  399. <xsl:for-each select="@*">
  400. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  401. </xsl:for-each>
  402. <xsl:apply-templates mode="upgradeInfo"/>
  403. </xsl:element>
  404. </xsl:template>
  405. <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  406. <!-- Copy all comments. -->
  407. <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  408. <xsl:template match="comment()">
  409. <xsl:copy-of select="."/>
  410. </xsl:template>
  411. </xsl:stylesheet>