nav2pages.xslt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. BI and PM: cpscrn
  5. (C) Copyright IBM Corp. 2005, 2011
  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. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  13. xmlns:nav="http://developer.cognos.com/schemas/cps/navigation/1/"
  14. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt">
  15. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  16. <xsl:variable name="customs" select="/root/customs/param"/>
  17. <xsl:variable name="meta" select="/root/fragment/meta"/>
  18. <xsl:variable name="excludeEmptyFolders">
  19. <xsl:call-template name="get-custom">
  20. <xsl:with-param name="name">excludeEmptyFolders</xsl:with-param>
  21. </xsl:call-template>
  22. </xsl:variable>
  23. <xsl:variable name="selected-tabs" select="/root/state/param[@name='selectedTabs']"/>
  24. <xsl:variable name="is-using-product-locale" select="$customs[@name='useProductLocaleForTabNames']='true'"/>
  25. <xsl:variable name="report-saved-output-height" select="$customs[@name='reportSavedOutputHeight']"/>
  26. <xsl:variable name="report-show-toolbar" select="$customs[@name='reportToolbar'] = 'true'"/>
  27. <xsl:variable name="calculated-height">
  28. <xsl:choose>
  29. <xsl:when test="(string($customs[@name='reportSavedOutputHeight']) != '')">
  30. <xsl:value-of select="$customs[@name='reportSavedOutputHeight']"/>
  31. </xsl:when>
  32. <xsl:otherwise>
  33. <xsl:text>365</xsl:text>
  34. </xsl:otherwise>
  35. </xsl:choose>
  36. </xsl:variable>
  37. <!--
  38. defines an attribute set to be applied on each page element
  39. -->
  40. <xsl:attribute-set name="page">
  41. <xsl:attribute name="title">
  42. <xsl:choose>
  43. <xsl:when test="$is-using-product-locale">
  44. <xsl:value-of select="nav:productLocaleName"/>
  45. </xsl:when>
  46. <xsl:otherwise>
  47. <xsl:value-of select="nav:name"/>
  48. </xsl:otherwise>
  49. </xsl:choose>
  50. </xsl:attribute>
  51. <xsl:attribute name="href">
  52. <xsl:choose>
  53. <xsl:when test="nav:type = 'package' and nav:subType = 'adaptiveAnalytics' and local-name() = 'item'">
  54. <xsl:text>/AApackage/</xsl:text>
  55. <xsl:value-of select="nav:internalId"/>
  56. </xsl:when>
  57. <!-- admin pages -->
  58. <xsl:when test="nav:type = 'pageletFolder'">
  59. <xsl:text>/booklet/</xsl:text>
  60. <xsl:value-of select="nav:internalId"/>
  61. </xsl:when>
  62. <xsl:when test="nav:type = 'shortcut'">
  63. <xsl:text>/cm/</xsl:text>
  64. <xsl:value-of select="nav:internalId"/>
  65. <xsl:text>?viewer-height=</xsl:text>
  66. <xsl:value-of select="$calculated-height"/>
  67. <xsl:text>&amp;cpscp_display_height=100%25</xsl:text>
  68. <xsl:text>&amp;output-height=100%25</xsl:text>
  69. <xsl:if test="nav:defaultPortalAction = 'run'">
  70. <xsl:text>&amp;p_reportLaunchOption=run</xsl:text>
  71. </xsl:if>
  72. <xsl:if test="$report-show-toolbar">
  73. <xsl:text>&amp;p_viewerToolbarNormalMode=showNormal</xsl:text>
  74. </xsl:if>
  75. </xsl:when>
  76. <xsl:otherwise>
  77. <xsl:text>/</xsl:text>
  78. <xsl:value-of select="nav:type"/>
  79. <xsl:text>/</xsl:text>
  80. <xsl:value-of select="nav:internalId"/>
  81. <xsl:text>?viewer-height=</xsl:text>
  82. <xsl:value-of select="$calculated-height"/>
  83. <xsl:text>&amp;cpscp_display_height=100%25</xsl:text>
  84. <xsl:text>&amp;output-height=100%25</xsl:text>
  85. <xsl:if test="nav:defaultPortalAction = 'run'">
  86. <xsl:text>&amp;p_reportLaunchOption=run</xsl:text>
  87. </xsl:if>
  88. <xsl:if test="$report-show-toolbar">
  89. <xsl:text>&amp;p_viewerToolbarNormalMode=showNormal</xsl:text>
  90. </xsl:if>
  91. </xsl:otherwise>
  92. </xsl:choose>
  93. </xsl:attribute>
  94. <xsl:attribute name="icon">
  95. <xsl:value-of select="nav:imgURL"/>
  96. </xsl:attribute>
  97. <xsl:attribute name="hidden">
  98. <xsl:choose>
  99. <xsl:when test="nav:hidden = 'true'">
  100. <xsl:text>true</xsl:text>
  101. </xsl:when>
  102. <xsl:otherwise>
  103. <xsl:text>false</xsl:text>
  104. </xsl:otherwise>
  105. </xsl:choose>
  106. </xsl:attribute>
  107. <xsl:attribute name="id">
  108. <xsl:value-of select="nav:internalId"/>
  109. </xsl:attribute>
  110. <xsl:attribute name="type">
  111. <xsl:value-of select="nav:type"/>
  112. </xsl:attribute>
  113. <xsl:attribute name="target">
  114. <xsl:if test="nav:type = 'shortcut'">
  115. <xsl:value-of select="nav:*/nav:type"/>
  116. </xsl:if>
  117. </xsl:attribute>
  118. <xsl:attribute name="permissions">
  119. <xsl:value-of select="nav:permissions"/>
  120. </xsl:attribute>
  121. </xsl:attribute-set>
  122. <!--
  123. MAIN - transforms the NAV's response into pages XML elements.
  124. -->
  125. <xsl:template match="/">
  126. <xsl:variable name="results" select="/root/input[@name='nav']/nav:requestResponse/nav:queryReplies/nav:queryReply"/>
  127. <xsl:variable name="container" select="$results[1]/nav:getContainerResponse/nav:container"/>
  128. <xsl:variable name="children" select="$results[2][not($excludeEmptyFolders='true')]/nav:searchResponse/nav:content/*"/>
  129. <xsl:variable name="firstlevel-has-children" select="$results[2]/nav:searchResponse/nav:content/*"/>
  130. <xsl:variable name="classes">
  131. <class>folder</class>
  132. <class>analysis</class>
  133. <class>document</class>
  134. <class>package</class>
  135. <class>pagelet</class>
  136. <class>pageletFolder</class>
  137. <class>powerPlayCube</class>
  138. <class>powerPlayReport</class>
  139. <class>powerPlay8Report</class>
  140. <class>query</class>
  141. <class>report</class>
  142. <class>reportView</class>
  143. <class>shortcut</class>
  144. <class>URL</class>
  145. </xsl:variable>
  146. <xsl:variable name="class-list">
  147. <xsl:for-each select="$classes/class"><xsl:value-of select="concat(., '|')"/></xsl:for-each>
  148. </xsl:variable>
  149. <xsl:variable name="originalPages">
  150. <xsl:copy-of select="/root/input[@name='pages']/pages"/>
  151. </xsl:variable>
  152. <xsl:variable name="pages">
  153. <xsl:choose>
  154. <!-- use the pages XML (from customization) -->
  155. <xsl:when test="/root/input[@name='pages']/pages">
  156. <!-- Use a copy of the pages element to create ids, to insulate those ids from changes elsewhere in the input document. -->
  157. <xsl:apply-templates select="$originalPages/*"/>
  158. </xsl:when>
  159. <!-- use the NAV response -->
  160. <xsl:when test="$container[1][nav:defaultAction]">
  161. <xsl:for-each select="$container[1]">
  162. <pages xsl:use-attribute-sets="page">
  163. <xsl:for-each select="$container/nav:content/*[nav:defaultAction][not(self::nav:shortcut) or contains($class-list, concat(./*/nav:type, '|'))]">
  164. <xsl:variable name="parentId" select="nav:id"/>
  165. <!-- hide a shortuct to a reportview with baseclass that is not in the supported list-->
  166. <xsl:if test="not(self::nav:shortcut and ./*/nav:type='reportView') or contains($class-list, concat(./*/nav:baseType, '|'))">
  167. <!-- hide a report view with base class that is not in the supported list -->
  168. <xsl:if test="not(nav:type = 'reportView') or contains($class-list, concat(nav:baseType, '|'))">
  169. <!-- When 'excludeEmptyFolders' flag is turned on, hide any container object that has no children -->
  170. <xsl:if test="not(self::nav:container) or not($excludeEmptyFolders='true') or count($firstlevel-has-children[nav:parentId = $parentId][nav:defaultAction]) > 0">
  171. <page xsl:use-attribute-sets="page">
  172. <xsl:if test="contains($selected-tabs, nav:internalId)">
  173. <xsl:attribute name="selected">true</xsl:attribute>
  174. </xsl:if>
  175. <xsl:call-template name="custom-properties"/>
  176. <xsl:for-each select="$children[nav:parentId = $parentId][nav:defaultAction][not(self::nav:shortcut) or contains($class-list, concat(./*/nav:type, '|'))]">
  177. <page xsl:use-attribute-sets="page">
  178. <xsl:if test="contains($selected-tabs, nav:internalId)">
  179. <xsl:attribute name="selected">true</xsl:attribute>
  180. </xsl:if>
  181. <xsl:call-template name="custom-properties"/>
  182. </page>
  183. </xsl:for-each>
  184. </page>
  185. </xsl:if>
  186. </xsl:if>
  187. </xsl:if>
  188. </xsl:for-each>
  189. </pages>
  190. </xsl:for-each>
  191. </xsl:when>
  192. <xsl:otherwise>
  193. <pages unavailable="true"/>
  194. </xsl:otherwise>
  195. </xsl:choose>
  196. </xsl:variable>
  197. <response>
  198. <xsl:variable name="refresh" select="string(/root/interactions/param[@name='refresh'])"/>
  199. <xsl:variable name="updateState" select="string(/root/interactions/param[@name='updateState'])"/>
  200. <xsl:variable name="level1-selected-page" select="($pages/pages/page[@selected='true'] | $pages/pages/page[position() = 1 and not($pages/pages/page[@selected='true'])])"/>
  201. <xsl:variable name="selected-page" select="($level1-selected-page/page[@selected='true'] | $level1-selected-page/page[position() = 1 and not($level1-selected-page/page[@selected='true'])] | $level1-selected-page[not(page)] )"/>
  202. <xsl:variable name="first-page" select="$selected-page[not($refresh = 'true' or $updateState = 'true')]"/>
  203. <fragment>
  204. <xsl:if test="$customs[@name='titleOptions']='selected'">
  205. <preferredTitle>
  206. <xsl:value-of select="$container/nav:name"/>
  207. </preferredTitle>
  208. </xsl:if>
  209. <xsl:if test="$first-page/@href != '' ">
  210. <!-- and add the first page subfragment -->
  211. <subfragment id="firstpage" href="{$first-page/@href}">
  212. <xsl:if test="$first-page/custom/param">
  213. <xsl:copy-of select="$first-page/custom"/>
  214. </xsl:if>
  215. <params>
  216. <param name="viewer-height">
  217. <xsl:value-of select="$calculated-height"/>
  218. </param>
  219. <param name="cpscp_display_height">100%</param>
  220. <param name="output-height">100%</param>
  221. </params>
  222. </subfragment>
  223. </xsl:if>
  224. </fragment>
  225. <!-- copy the new pages XML -->
  226. <xsl:copy-of select="$pages"/>
  227. </response>
  228. </xsl:template>
  229. <xsl:template match="pages|page">
  230. <xsl:copy>
  231. <xsl:copy-of select="@*"/>
  232. <xsl:variable name="id">
  233. <xsl:choose>
  234. <xsl:when test="@id">
  235. <xsl:value-of select="@id"/>
  236. </xsl:when>
  237. <xsl:otherwise>
  238. <xsl:value-of select="generate-id()"/>
  239. </xsl:otherwise>
  240. </xsl:choose>
  241. </xsl:variable>
  242. <xsl:if test="not(@id)">
  243. <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
  244. </xsl:if>
  245. <xsl:if test="contains($selected-tabs,$id)">
  246. <xsl:attribute name="selected">true</xsl:attribute>
  247. </xsl:if>
  248. <xsl:apply-templates/>
  249. </xsl:copy>
  250. </xsl:template>
  251. <!--
  252. get-custom: get a value from either the customs or the META's default value
  253. -->
  254. <xsl:template name="get-custom">
  255. <xsl:param name="name"/>
  256. <xsl:choose>
  257. <xsl:when test="$customs[@name=$name]">
  258. <xsl:value-of select="$customs[@name=$name]"/>
  259. </xsl:when>
  260. <xsl:otherwise>
  261. <xsl:value-of select="$meta/customProperties[@name=$name]/default/value"/>
  262. </xsl:otherwise>
  263. </xsl:choose>
  264. </xsl:template>
  265. <xsl:template name="custom-properties">
  266. <custom>
  267. <!-- cogadmin pages -->
  268. <xsl:if test="nav:type = 'pageletFolder'">
  269. <param name="view">vtabs</param>
  270. <param name="showicons">true</param>
  271. <param name="useProductLocaleForTabNames">true</param>
  272. </xsl:if>
  273. </custom>
  274. </xsl:template>
  275. </xsl:stylesheet>