nav2pages.xslt 8.8 KB

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