drillthrough.xslt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: Viewer
  5. (C) Copyright IBM Corp. 2001, 2011
  6. US Government Users Restricted Rights - Use, duplication or
  7. disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. -->
  9. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
  10. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  11. xmlns:bus="http://developer.cognos.com/schemas/bibus/3/">
  12. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  13. <xsl:template match="/getAction">
  14. <xsl:variable name="path"><xsl:value-of select="/*[local-name()='getAction']/drillAction/param[@name='ui.object']"/></xsl:variable>
  15. <xsl:variable name="cmQueryResponseRootNode" select="/*[local-name()='getAction']/*[local-name()='cmResponseNode'][@refId=$path]"/>
  16. <xsl:variable name="cmQueryResponseNode" select="$cmQueryResponseRootNode/*[local-name()='queryResponse']/*[local-name()='queryReply']/*[local-name()='query' or local-name()='report' or local-name()='analysis' or local-name()='reportView'][*[local-name()='searchPath']=$path]"/>
  17. <xsl:variable name="method"><xsl:value-of select="/*[local-name()='getAction']/*[local-name()='drillAction']/*[local-name()='param'][@name='ui.action']"/></xsl:variable>
  18. <xsl:variable name="desiredOutputFormat"><xsl:value-of select="/*[local-name()='getAction']/*[local-name()='drillAction']/*[local-name()='param'][@name='run.outputFormat']"/></xsl:variable>
  19. <xsl:variable name="hasSavedOutput">
  20. <xsl:choose>
  21. <xsl:when test="$cmQueryResponseRootNode/*[local-name()='queryResponse']/*[local-name()='queryReply']/*[local-name()='output']">true</xsl:when>
  22. <xsl:otherwise>false</xsl:otherwise>
  23. </xsl:choose>
  24. </xsl:variable>
  25. <xsl:variable name="desiredMethod">
  26. <xsl:call-template name="getDesiredMethod">
  27. <xsl:with-param name="cmQueryResponseNode" select="$cmQueryResponseNode"/>
  28. <xsl:with-param name="method" select="$method"/>
  29. <xsl:with-param name="hasSavedOutput" select="$hasSavedOutput"/>
  30. </xsl:call-template>
  31. </xsl:variable>
  32. <xsl:variable name="outputFormat">
  33. <xsl:call-template name="getPermittedOutputFormat">
  34. <xsl:with-param name="cmQueryResponseNode" select="$cmQueryResponseNode"/>
  35. <xsl:with-param name="desiredOutputFormat" select="$desiredOutputFormat"/>
  36. <xsl:with-param name="desiredMethod" select="$desiredMethod"/>
  37. </xsl:call-template>
  38. </xsl:variable>
  39. <xsl:element name="env">
  40. <param name="ui.action"><xsl:value-of select="$desiredMethod"/></param>
  41. <param name="run.outputFormat"><xsl:value-of select="$outputFormat"/></param>
  42. <xsl:choose>
  43. <xsl:when test="string(/getAction/drillAction/param[@name='run.prompt']) = 'true'">
  44. <param name="run.prompt">true</param>
  45. </xsl:when>
  46. <xsl:otherwise>
  47. <param name="run.prompt">false</param>
  48. </xsl:otherwise>
  49. </xsl:choose>
  50. <xsl:choose>
  51. <xsl:when test="$desiredMethod = 'view'">
  52. <param name="ui.format"><xsl:value-of select="$outputFormat"/></param>
  53. <param name="ui.object">
  54. <xsl:text>defaultOutput(</xsl:text>
  55. <xsl:value-of select="/getAction/drillAction/param[@name='ui.object']"/>
  56. <xsl:text>,&apos;</xsl:text>
  57. <xsl:value-of select="$outputFormat"/>
  58. <xsl:text>&apos;, &apos;&apos;)</xsl:text>
  59. </param>
  60. </xsl:when>
  61. <xsl:otherwise>
  62. <param name="ui.object"><xsl:value-of select="/getAction/drillAction/param[@name='ui.object']"/></param>
  63. </xsl:otherwise>
  64. </xsl:choose>
  65. <xsl:for-each select="/getAction/drillAction/param[not(@name='ui.action' or @name='run.outputFormat' or @name='ui.format' or @name='ui.object')]">
  66. <xsl:element name="param">
  67. <xsl:attribute name="name"><xsl:value-of select="./@name"/></xsl:attribute>
  68. <xsl:value-of select="."/>
  69. </xsl:element>
  70. </xsl:for-each>
  71. </xsl:element>
  72. </xsl:template>
  73. <xsl:template match="/getTargets">
  74. <xsl:for-each select="/*[local-name()='getTargets']/*[local-name()='drillTargets']/*[local-name()='drillTarget']">
  75. <xsl:variable name="path"><xsl:value-of select="./@path"/></xsl:variable>
  76. <xsl:variable name="desiredOutputFormat"><xsl:value-of select="./@outputFormat"/></xsl:variable>
  77. <xsl:variable name="cmQueryResponseRootNode" select="/*[local-name()='getTargets']/*[local-name()='cmResponseNode'][@refId=$path]"/>
  78. <xsl:variable name="cmQueryResponseNode" select="$cmQueryResponseRootNode/*[local-name()='queryResponse']/*[local-name()='queryReply']/*[local-name()='query' or local-name()='report' or local-name()='analysis' or local-name()='reportView'][*[local-name()='searchPath']=$path]"/>
  79. <xsl:choose>
  80. <xsl:when test="$cmQueryResponseNode">
  81. <xsl:variable name="hasSavedOutput">
  82. <xsl:choose>
  83. <xsl:when test="$cmQueryResponseRootNode/*[local-name()='queryResponse']/*[local-name()='queryReply']/*[local-name()='output']">true</xsl:when>
  84. <xsl:otherwise>false</xsl:otherwise>
  85. </xsl:choose>
  86. </xsl:variable>
  87. <xsl:variable name="desiredMethod">
  88. <xsl:call-template name="getDesiredMethod">
  89. <xsl:with-param name="cmQueryResponseNode" select="$cmQueryResponseNode"/>
  90. <xsl:with-param name="method" select="./@method"/>
  91. <xsl:with-param name="hasSavedOutput" select="$hasSavedOutput"/>
  92. </xsl:call-template>
  93. </xsl:variable>
  94. <xsl:if test="$desiredMethod!=''">
  95. <xsl:variable name="outputFormat">
  96. <xsl:call-template name="getPermittedOutputFormat">
  97. <xsl:with-param name="cmQueryResponseNode" select="$cmQueryResponseNode"/>
  98. <xsl:with-param name="desiredOutputFormat" select="$desiredOutputFormat"/>
  99. <xsl:with-param name="desiredMethod" select="$desiredMethod"/>
  100. </xsl:call-template>
  101. </xsl:variable>
  102. <xsl:element name="drillTarget">
  103. <xsl:attribute name="method">
  104. <xsl:value-of select="$desiredMethod"/>
  105. </xsl:attribute>
  106. <xsl:attribute name="outputFormat">
  107. <xsl:value-of select="$outputFormat"/>
  108. </xsl:attribute>
  109. <xsl:choose>
  110. <xsl:when test="$desiredMethod = 'view'">
  111. <xsl:attribute name="format">
  112. <xsl:value-of select="$outputFormat"/>
  113. </xsl:attribute>
  114. <xsl:attribute name="path">
  115. <xsl:text>defaultOutput(</xsl:text>
  116. <xsl:value-of select="./@path"/>
  117. <xsl:text>,&apos;</xsl:text>
  118. <xsl:value-of select="$outputFormat"/>
  119. <xsl:text>&apos;, &apos;&apos;)</xsl:text>
  120. </xsl:attribute>
  121. </xsl:when>
  122. <xsl:otherwise>
  123. <xsl:attribute name="path">
  124. <xsl:value-of select="./@path"/>
  125. </xsl:attribute>
  126. </xsl:otherwise>
  127. </xsl:choose>
  128. <xsl:for-each select="@*[not(name()='method' or name()='outputFormat' or name()='format' or name()='path')]">
  129. <xsl:attribute name="{name()}">
  130. <xsl:value-of select="."/>
  131. </xsl:attribute>
  132. </xsl:for-each>
  133. <xsl:copy-of select="./*"/>
  134. </xsl:element>
  135. </xsl:if>
  136. </xsl:when>
  137. <xsl:otherwise>
  138. <xsl:copy-of select="."/>
  139. </xsl:otherwise>
  140. </xsl:choose>
  141. </xsl:for-each>
  142. </xsl:template>
  143. <xsl:template name="getPermittedOutputFormat">
  144. <xsl:param name="cmQueryResponseNode"/>
  145. <xsl:param name="desiredOutputFormat"/>
  146. <xsl:param name="desiredMethod"/>
  147. <xsl:choose>
  148. <xsl:when test="$desiredOutputFormat='default'">
  149. <xsl:choose>
  150. <xsl:when test="$desiredMethod='view'">
  151. <xsl:choose>
  152. <xsl:when test="$cmQueryResponseNode/*[local-name()='defaultOutputFormat']!=''">
  153. <xsl:value-of select="$cmQueryResponseNode/*[local-name()='defaultOutputFormat']"/>
  154. </xsl:when>
  155. <xsl:otherwise>
  156. <xsl:text>HTML</xsl:text>
  157. </xsl:otherwise>
  158. </xsl:choose>
  159. </xsl:when>
  160. <xsl:otherwise>
  161. <xsl:choose>
  162. <xsl:when test="$cmQueryResponseNode/*[local-name()='executionFormat']!=''">
  163. <xsl:value-of select="$cmQueryResponseNode/*[local-name()='executionFormat']"/>
  164. </xsl:when>
  165. <xsl:otherwise>
  166. <xsl:text>HTML</xsl:text>
  167. </xsl:otherwise>
  168. </xsl:choose>
  169. </xsl:otherwise>
  170. </xsl:choose>
  171. </xsl:when>
  172. <xsl:otherwise>
  173. <xsl:value-of select="$desiredOutputFormat"/>
  174. </xsl:otherwise>
  175. </xsl:choose>
  176. </xsl:template>
  177. <xsl:template name="getDesiredMethod">
  178. <xsl:param name="cmQueryResponseNode"/>
  179. <xsl:param name="method"/>
  180. <xsl:param name="hasSavedOutput"/>
  181. <xsl:choose>
  182. <xsl:when test="$method='edit'">
  183. <xsl:call-template name="getEditMethod">
  184. <xsl:with-param name="cmQueryResponseNode" select="$cmQueryResponseNode"/>
  185. </xsl:call-template>
  186. </xsl:when>
  187. <xsl:when test="$method='default'">
  188. <xsl:choose>
  189. <xsl:when test="$cmQueryResponseNode/*[local-name()='defaultPortalAction']='viewOutput'">
  190. <xsl:choose>
  191. <xsl:when test="$hasSavedOutput='true'">view</xsl:when>
  192. <!-- if no output is saved, default to execute -->
  193. <xsl:otherwise>
  194. <xsl:call-template name="getEditMethod">
  195. <xsl:with-param name="cmQueryResponseNode" select="$cmQueryResponseNode"/>
  196. </xsl:call-template>
  197. </xsl:otherwise>
  198. </xsl:choose>
  199. </xsl:when>
  200. <xsl:when test="$cmQueryResponseNode/*[local-name()='defaultPortalAction']='run'">
  201. <xsl:text>run</xsl:text>
  202. </xsl:when>
  203. <xsl:when test="$cmQueryResponseNode/*[local-name()='defaultPortalAction']='edit'">
  204. <xsl:call-template name="getEditMethod">
  205. <xsl:with-param name="cmQueryResponseNode" select="$cmQueryResponseNode"/>
  206. </xsl:call-template>
  207. </xsl:when>
  208. <xsl:otherwise>
  209. <!--we may not have read permissions on this obj, if that's the case, default the action to execute-->
  210. <xsl:text>run</xsl:text>
  211. </xsl:otherwise>
  212. </xsl:choose>
  213. </xsl:when>
  214. <xsl:when test="$method='view'">
  215. <xsl:choose>
  216. <xsl:when test="$hasSavedOutput='true'">view</xsl:when>
  217. <!-- if no output is saved, default to execute -->
  218. <xsl:otherwise>
  219. <xsl:call-template name="getEditMethod">
  220. <xsl:with-param name="cmQueryResponseNode" select="$cmQueryResponseNode"/>
  221. </xsl:call-template>
  222. </xsl:otherwise>
  223. </xsl:choose>
  224. </xsl:when>
  225. <xsl:otherwise>
  226. <xsl:value-of select="$method"/>
  227. </xsl:otherwise>
  228. </xsl:choose>
  229. </xsl:template>
  230. <xsl:template name="getEditMethod">
  231. <xsl:param name="cmQueryResponseNode"/>
  232. <xsl:choose>
  233. <xsl:when test="$cmQueryResponseNode/*[local-name()='objectClass']='query'">
  234. <xsl:text>editQuery</xsl:text>
  235. </xsl:when>
  236. <xsl:when test="$cmQueryResponseNode/*[local-name()='objectClass']='analysis'">
  237. <xsl:text>editAnalysis</xsl:text>
  238. </xsl:when>
  239. <!-- for now, if the report author has set the target to be edit, and the target is a report studio report, just do an execute -->
  240. <xsl:otherwise>
  241. <xsl:text>run</xsl:text>
  242. </xsl:otherwise>
  243. </xsl:choose>
  244. </xsl:template>
  245. <xsl:template match="/appendDrillSpecs">
  246. <xsl:for-each select="/*[local-name()='appendDrillSpecs']/*[local-name()='drillTargets']/*[local-name()='drillTarget']">
  247. <xsl:element name="drillTarget">
  248. <xsl:variable name="drillIdx"><xsl:value-of select="./@drillIdx"/></xsl:variable>
  249. <xsl:for-each select="/*[local-name()='appendDrillSpecs']/*[local-name()='drillSpecs']/*/*[local-name()='DRILL'][(position()-1) = $drillIdx]/@*[not(name()='label')]">
  250. <xsl:attribute name="{name()}">
  251. <xsl:value-of select="."/>
  252. </xsl:attribute>
  253. </xsl:for-each>
  254. <xsl:attribute name="label">
  255. <xsl:choose>
  256. <xsl:when test="string(./@label) != ''">
  257. <xsl:value-of select="./@label"/>
  258. </xsl:when>
  259. <xsl:otherwise>
  260. <xsl:value-of select="/*[local-name()='appendDrillSpecs']/*[local-name()='drillSpecs']/*/*[local-name()='DRILL'][(position()-1) = $drillIdx]/@label"/>
  261. </xsl:otherwise>
  262. </xsl:choose>
  263. </xsl:attribute>
  264. <xsl:for-each select="./*[local-name()='drillParameter']">
  265. <drillParameter>
  266. <xsl:copy-of select="@*"/>
  267. <xsl:variable name="parameterName" select="@name"/>
  268. <xsl:if test="/*[local-name()='appendDrillSpecs']/*[local-name()='drillSpecs']/*/*[local-name()='DRILL'][(position()-1) = $drillIdx]/PARAMETER-PROPERTIES/Parameter[@name=string($parameterName)]">
  269. <xsl:attribute name="propertyToPass">
  270. <xsl:value-of select="/*[local-name()='appendDrillSpecs']/*[local-name()='drillSpecs']/*/*[local-name()='DRILL'][(position()-1) = $drillIdx]/PARAMETER-PROPERTIES/Parameter/@propertyToPass"/>
  271. </xsl:attribute>
  272. </xsl:if>
  273. <xsl:copy-of select="./*"/>
  274. </drillParameter>
  275. </xsl:for-each>
  276. <xsl:copy-of select="./*[local-name()!='drillParameter']"/>
  277. <xsl:copy-of select="/*[local-name()='appendDrillSpecs']/*[local-name()='drillSpecs']/*/*[local-name()='DRILL'][(position()-1) = $drillIdx]/*[local-name()!='PARAMETER-PROPERTIES']"/>
  278. </xsl:element>
  279. </xsl:for-each>
  280. </xsl:template>
  281. <xsl:template match="/sourceContextNodes">
  282. <xsl:choose>
  283. <xsl:when test="/sourceContextNodes/*[local-name()='targetParameters']/*[local-name()='promptDataSourceResponse']">
  284. <targetParameters>
  285. <parameters>
  286. <xsl:copy-of select="/sourceContextNodes/*[local-name()='targetParameters']/*[local-name()='promptDataSourceResponse']/*/*/*[local-name()='details']/*[local-name()='item'][@xsi:type='bus:asynchDetailParameters']/*[local-name()='parameters']/*"/>
  287. </parameters>
  288. </targetParameters>
  289. <sourceContextValues>
  290. <parameterValues>
  291. <xsl:copy-of select="/sourceContextNodes/*[local-name()='sourceContextValues']/*/*"/>
  292. </parameterValues>
  293. </sourceContextValues>
  294. <dataSourceConnection>
  295. <xsl:copy-of select="/sourceContextNodes/*[local-name()='targetParameters']/*[local-name()='promptDataSourceResponse']/*/*/*[local-name()='details']/*[local-name()='item'][@xsi:type='bus:asynchDetailParameterValues']/*[local-name()='parameters']"/>
  296. </dataSourceConnection>
  297. </xsl:when>
  298. <xsl:otherwise>
  299. <xsl:copy-of select="/sourceContextNodes/*"/>
  300. </xsl:otherwise>
  301. </xsl:choose>
  302. </xsl:template>
  303. <xsl:template match="*[local-name()='extractCredential']">
  304. <xsl:copy-of select="/*[local-name()='extractCredential']/*[local-name()='sourceParameterValues']/*/*[local-name()='item'][starts-with(string(./*[local-name()='name']),'credential:')]"/>
  305. <xsl:for-each select="/*[local-name()='extractCredential']/*[local-name()='targetParameters']/*[local-name()='parameters']/*[local-name()='item'][@xsi:type='bus:parameterDataSource']">
  306. <xsl:variable name="dataSourceParameterName"><xsl:value-of select="./*[local-name()='name']"/></xsl:variable>
  307. <xsl:copy-of select="/*[local-name()='extractCredential']/*[local-name()='sourceParameterValues']/*/*[local-name()='item'][./*[local-name()='name']=$dataSourceParameterName]"/>
  308. </xsl:for-each>
  309. </xsl:template>
  310. <!--When doing a drill through, check to see if there are parameter values being passed in. If so, set the prompt run option to false, otherwise set it to true.
  311. By setting the prompt run option to true, if there are prompt pages to be displayed, the report server will display the authored prompt pages instead of the
  312. default prompt page.
  313. -->
  314. <xsl:template match="*[local-name()='getPromptRunOption']">
  315. <param name="run.prompt">
  316. <xsl:choose>
  317. <xsl:when test="/*[local-name()='getPromptRunOption']/*/*">
  318. <xsl:text>false</xsl:text>
  319. </xsl:when>
  320. <xsl:otherwise>
  321. <xsl:text>true</xsl:text>
  322. </xsl:otherwise>
  323. </xsl:choose>
  324. </param>
  325. </xsl:template>
  326. </xsl:stylesheet>