prepare.xslt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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" xmlns:encodingUtils="com.cognos.portal.utils.EncodingUtils">
  9. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  10. <xsl:variable name="controllerParams" select="/root/controllerParams/param"/>
  11. <xsl:variable name="customs" select="/root/customs/param"/>
  12. <xsl:variable name="meta" select="/root/fragment/meta"/>
  13. <xsl:variable name="backURL" select="/root/interactions/param[@name='backURL']"/>
  14. <xsl:template match="/">
  15. <response>
  16. <xsl:if test="not($controllerParams[@name='frag-directive'] = 'meta-only')">
  17. <xsl:variable name="pages">
  18. <xsl:choose>
  19. <!-- pages is statically defined as XML -->
  20. <xsl:when test="$customs[@name='pages']/pages">
  21. <xsl:copy-of select="$customs[@name='pages']/pages"/>
  22. </xsl:when>
  23. <!-- pages is statically defined as text, so convert it to XML -->
  24. <xsl:when test="normalize-space($customs[@name='pages']) != ''">
  25. <xsl:value-of select="$customs[@name='pages']" disable-output-escaping="yes"/>
  26. </xsl:when>
  27. </xsl:choose>
  28. </xsl:variable>
  29. <xsl:variable name="folder">
  30. <xsl:call-template name="get-custom">
  31. <xsl:with-param name="name">folder</xsl:with-param>
  32. </xsl:call-template>
  33. </xsl:variable>
  34. <xsl:variable name="maxlevels">
  35. <xsl:call-template name="get-custom">
  36. <xsl:with-param name="name">maxlevels</xsl:with-param>
  37. </xsl:call-template>
  38. </xsl:variable>
  39. <xsl:variable name="header">
  40. <xsl:call-template name="get-custom">
  41. <xsl:with-param name="name">header</xsl:with-param>
  42. </xsl:call-template>
  43. </xsl:variable>
  44. <xsl:variable name="footer">
  45. <xsl:call-template name="get-custom">
  46. <xsl:with-param name="name">footer</xsl:with-param>
  47. </xsl:call-template>
  48. </xsl:variable>
  49. <xsl:variable name="fixed">
  50. <xsl:call-template name="get-custom">
  51. <xsl:with-param name="name">fixed</xsl:with-param>
  52. </xsl:call-template>
  53. </xsl:variable>
  54. <xsl:variable name="view">
  55. <xsl:call-template name="get-custom">
  56. <xsl:with-param name="name">view</xsl:with-param>
  57. </xsl:call-template>
  58. </xsl:variable>
  59. <xsl:variable name="excludeEmptyFolders">
  60. <xsl:call-template name="get-custom">
  61. <xsl:with-param name="name">excludeEmptyFolders</xsl:with-param>
  62. </xsl:call-template>
  63. </xsl:variable>
  64. <fragment>
  65. <xsl:if test="$fixed = 'true'">
  66. <info>
  67. <xsl:copy-of select="/root/fragment/info/*"/>
  68. <display>fixed</display>
  69. </info>
  70. </xsl:if>
  71. <xsl:if test="$header != ''">
  72. <xsl:variable name="myHref">
  73. <xsl:call-template name="gen-href">
  74. <xsl:with-param name="value" select="$header"/>
  75. </xsl:call-template>
  76. </xsl:variable>
  77. <subfragment id="header" href="{$myHref}">
  78. <params><!-- backURL needs to be kept in a cdata block for now. This is due to a bug in the server, where text is being truncated at the first entity -->
  79. <param name="backURL">
  80. <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text><xsl:value-of select="$backURL" disable-output-escaping="yes"/><xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
  81. </param>
  82. </params>
  83. </subfragment>
  84. </xsl:if>
  85. <xsl:if test="$footer != ''">
  86. <subfragment id="footer">
  87. <xsl:attribute name="href">
  88. <xsl:call-template name="gen-href">
  89. <xsl:with-param name="value" select="$footer"/>
  90. </xsl:call-template>
  91. </xsl:attribute>
  92. </subfragment>
  93. </xsl:if>
  94. <xsl:if test="not($controllerParams[@name='frag-view'])">
  95. <newView>
  96. <xsl:value-of select="$view"/>
  97. </newView>
  98. </xsl:if>
  99. </fragment>
  100. <xsl:choose>
  101. <xsl:when test="$pages/pages">
  102. <!-- copy as XML elements -->
  103. <xsl:copy-of select="$pages/pages"/>
  104. </xsl:when>
  105. <xsl:when test="$pages != ''">
  106. <!-- copy as disabled-escaping text -->
  107. <xsl:copy-of select="$pages"/>
  108. </xsl:when>
  109. <xsl:otherwise>
  110. <!-- no pages xml or selected folder -->
  111. <pages no-source="true"/>
  112. </xsl:otherwise>
  113. </xsl:choose>
  114. </xsl:if>
  115. <xsl:if test="string(/root/interactions/param[@name='selectedTabs'])!=''">
  116. <state>
  117. <xsl:copy-of select="/root/interactions/param[@name='selectedTabs']"/>
  118. </state>
  119. </xsl:if>
  120. </response>
  121. </xsl:template>
  122. <!--
  123. gen-cmpath: generate a CM path syntax for NAV
  124. -->
  125. <xsl:template name="gen-cmpath">
  126. <xsl:param name="value"/>
  127. <xsl:choose>
  128. <xsl:when test="starts-with($value, 'path:')">
  129. <xsl:value-of select="$value"/>
  130. </xsl:when>
  131. <xsl:when test="starts-with($value, 'storeID(')">
  132. <xsl:text>path:</xsl:text>
  133. <xsl:value-of select="$value"/>
  134. </xsl:when>
  135. <xsl:otherwise>
  136. <xsl:text>path:storeID('</xsl:text>
  137. <xsl:value-of select="$value"/>
  138. <xsl:text>')</xsl:text>
  139. </xsl:otherwise>
  140. </xsl:choose>
  141. </xsl:template>
  142. <!--
  143. gen-href: generate href based on $value
  144. -->
  145. <xsl:template name="gen-href">
  146. <xsl:param name="value"/>
  147. <xsl:choose>
  148. <xsl:when test="starts-with($value, '/')">
  149. <xsl:value-of select="$value"/>
  150. </xsl:when>
  151. <xsl:when test="contains($value, '://')">
  152. <xsl:value-of select="$value"/>
  153. </xsl:when>
  154. <xsl:otherwise>
  155. <xsl:text>/cm?path=</xsl:text>
  156. <xsl:value-of select="$value"/>
  157. </xsl:otherwise>
  158. </xsl:choose>
  159. </xsl:template>
  160. <!--
  161. get-custom: get a value from either the customs or the META's default value
  162. -->
  163. <xsl:template name="get-custom">
  164. <xsl:param name="name"/>
  165. <xsl:choose>
  166. <xsl:when test="$customs[@name=$name]">
  167. <xsl:value-of select="$customs[@name=$name]"/>
  168. </xsl:when>
  169. <xsl:otherwise>
  170. <xsl:value-of select="$meta/customProperties[@name=$name]/default/value"/>
  171. </xsl:otherwise>
  172. </xsl:choose>
  173. </xsl:template>
  174. </xsl:stylesheet>