gen-module.xslt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: ps
  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"
  13. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  14. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  15. xmlns:c8="http://developer.cognos.com/schemas/xmldata/1/"
  16. xmlns:nav="http://developer.cognos.com/schemas/cps/navigation/1/"
  17. xmlns:xts="http://developer.cognos.com/schemas/xts/"
  18. xmlns:xos="http://developer.cognos.com/schemas/xts/output/"
  19. xmlns:cs="http://developer.cognos.com/schemas/cs">
  20. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  21. <xsl:param name="gw" select="''"/>
  22. <xsl:variable name="search-url">
  23. <xsl:value-of select="$gw"/>
  24. <xsl:text/>/gosearch?csn.terms=<xsl:text/>
  25. <xsl:value-of select="/root/env/param[@name='query']"/>
  26. </xsl:variable>
  27. <!-- Did we get any results? -->
  28. <xsl:variable name="results">
  29. <xsl:choose>
  30. <xsl:when test="/root/burgundy/cs:document/cs:result/cs:extensions/cs:resultCount != '0'">burgundy</xsl:when>
  31. <xsl:when test="/root/nav:searchResponse/nav:content/*">cmsearch</xsl:when>
  32. <xsl:when test="/root/report | /root/chart">cm</xsl:when>
  33. <xsl:when test="string(/root/metrics/MetricShortStats/image/row/uri) != ''">metric</xsl:when>
  34. <xsl:when test="string(/root/metrics/ob_server/ob_response/image/row/uri) != ''">metric</xsl:when>
  35. <xsl:otherwise>none</xsl:otherwise>
  36. </xsl:choose>
  37. </xsl:variable>
  38. <!-- Defines the URL that goes under the Title in the response -->
  39. <xsl:variable name="the-url">
  40. <xsl:choose>
  41. <xsl:when test="$results = 'metric' or $results = 'cm'">
  42. <xsl:value-of select="$gw"/>?b_action=xts.run&amp;m=onebox/launch.xts<xsl:text/>
  43. <xsl:choose>
  44. <xsl:when test="$results = 'metric'">
  45. <xsl:variable name="path">/content//package[@name='<xsl:value-of select="/root/metrics/packagePath"/>']</xsl:variable>
  46. <xsl:text/>&amp;path=<xsl:value-of select="xtsext:protect(xtsext:urlencode(string($path)),'url','searchPath','getdata')"/>
  47. </xsl:when>
  48. <xsl:otherwise>
  49. <xsl:text/>&amp;id=<xsl:value-of select="/root/item/storeID/value"/>
  50. </xsl:otherwise>
  51. </xsl:choose>
  52. </xsl:when>
  53. <xsl:otherwise>
  54. <xsl:value-of select="$search-url"/>
  55. </xsl:otherwise>
  56. </xsl:choose>
  57. </xsl:variable>
  58. <xsl:variable name="the-name">
  59. <xsl:choose>
  60. <xsl:when test="string(/root/item[1]/defaultName/value) != ''">
  61. <xsl:value-of select="/root/item[1]/defaultName/value"/>
  62. </xsl:when>
  63. <xsl:when test="string(/root/metrics/MetricShortStats/imageTitle/row/title)!=''">
  64. <xsl:value-of select="/root/metrics/MetricShortStats/imageTitle/row/title"/>
  65. </xsl:when>
  66. <xsl:when test="string(/root/metrics/ob_server/ob_response/imageTitle/row/title)!=''">
  67. <xsl:value-of select="/root/metrics/ob_server/ob_response/imageTitle/row/title"/>
  68. </xsl:when>
  69. <xsl:otherwise>
  70. <xsl:text/><xts:string id="IDS_OBX_COGNOS_GO"/><xsl:text/>
  71. </xsl:otherwise>
  72. </xsl:choose>
  73. </xsl:variable>
  74. <xsl:variable name="img-source">
  75. <xsl:choose>
  76. <xsl:when test="/root/chart">
  77. <xsl:variable name="chart-store-id">storeID('<xsl:value-of select="/root/chart"/>')</xsl:variable>
  78. <xsl:value-of select="$gw"/>
  79. <xsl:text/>?SM=query&amp;search=<xsl:value-of select="xtsext:protect($chart-store-id,'none','cmid','getdata')"/>
  80. <xsl:text/>&amp;SA=propEnum,properties&amp;ITEM=data&amp;EA=&amp;SS=queryOptions,options&amp;dataEncoding=MIME&amp;ES=&amp;EM=<xsl:text/>
  81. </xsl:when>
  82. <xsl:when test="string(/root/metrics/MetricShortStats/image/row/uri) != ''">
  83. <xsl:value-of select="/root/metrics/MetricShortStats/image/row/uri"/>
  84. </xsl:when>
  85. <xsl:when test="string(/root/metrics/ob_server/ob_response/image/row/uri) != ''">
  86. <xsl:value-of select="/root/metrics/ob_server/ob_response/image/row/uri"/>
  87. </xsl:when>
  88. <xsl:otherwise>
  89. <xsl:value-of select="substring-before($gw, '/cgi-bin')"/>
  90. <xsl:text/>/onebox/cognos8_40.gif<xsl:text/>
  91. </xsl:otherwise>
  92. </xsl:choose>
  93. </xsl:variable>
  94. <xsl:key name="class-names" match="/root/objectClass/class" use="@name"/>
  95. <xsl:template match="/root">
  96. <xos:part>
  97. <xos:entityHeader>
  98. <xos:param name="Content-Type">text/xml; charset=utf-8</xos:param>
  99. </xos:entityHeader>
  100. <xos:entityBody>
  101. <xsl:variable name="canDebug" select="string(/root/env/param[@name='d'])='1' and string(/root/debug/debugSwitch) != 'disable'"/>
  102. <xsl:if test="$canDebug">
  103. <xsl:text disable-output-escaping="yes">&lt;debug&gt;</xsl:text>
  104. </xsl:if>
  105. <OneBoxResults>
  106. <provider><xts:string id="IDS_OBX_PROVIDER_RESULTS"/></provider>
  107. <title>
  108. <urlText><xsl:value-of select="$the-name"/></urlText>
  109. <urlLink><xsl:value-of select="$the-url"/></urlLink>
  110. </title>
  111. <IMAGE_SOURCE>
  112. <xsl:value-of select="$img-source"/>
  113. </IMAGE_SOURCE>
  114. <xsl:if test="$results != 'none'">
  115. <MODULE_RESULT resultCode="success" cogType="title">
  116. <xsl:if test="string(/root/env/param[@name='lang'])!=''">
  117. <xsl:attribute name="xml:lang"><xsl:value-of select="/root/env/param[@name='lang']"/></xsl:attribute>
  118. </xsl:if>
  119. <xsl:if test="$results != 'burgundy'">
  120. <Field name="brand"><xts:string id="IDS_COGNOS_REPORTS"/></Field>
  121. </xsl:if>
  122. <xsl:if test="$results = 'burgundy' or $results = 'cmsearch'">
  123. <Field name="results">&#160;<xts:string id="IDS_OBX_RESULTS_FOR"/>&#160;<xsl:text/></Field>
  124. <Field name="query"><xsl:value-of select="/root/env/param[@name='query']"/></Field>
  125. <xsl:if test="$results = 'burgundy'">
  126. <Field name="count"><xsl:text/>&#160;<xts:string id="IDS_OBX_ABOUT"><xts:param name="obx_count"><xsl:value-of select="burgundy/cs:document/cs:result/cs:extensions/cs:resultCount"/></xts:param></xts:string></Field>
  127. </xsl:if>
  128. </xsl:if>
  129. <Field name="moreResults"><xts:string id="IDS_OBX_MORE_RESULTS"/></Field>
  130. <Field name="searchURL"><xsl:value-of select="$search-url"/></Field>
  131. </MODULE_RESULT>
  132. </xsl:if>
  133. <xsl:apply-templates select="report | burgundy | nav:searchResponse | metrics/MetricShortStats | metrics/ob_server/ob_response | error"/>
  134. </OneBoxResults>
  135. <xsl:if test="$canDebug">
  136. <xsl:copy-of select="."/>
  137. <results><xsl:value-of select="$results"/></results>
  138. <xsl:text disable-output-escaping="yes">&lt;/debug&gt;</xsl:text>
  139. </xsl:if>
  140. </xos:entityBody>
  141. </xos:part>
  142. </xsl:template>
  143. <!-- Handle XHTML reports -->
  144. <xsl:template match="report">
  145. <!-- grab just the first page-body -->
  146. <xsl:apply-templates select="descendant::td[@class='pb'][1]"/>
  147. </xsl:template>
  148. <xsl:template match="td[@class='pb']">
  149. <xsl:for-each select="table/tr[position()&lt;5]">
  150. <MODULE_RESULT resultCode="success">
  151. <U><xsl:value-of select="$the-url"/></U>
  152. <xsl:apply-templates select="td[position()&lt;9]"/>
  153. </MODULE_RESULT>
  154. </xsl:for-each>
  155. </xsl:template>
  156. <xsl:template match="td[@class='xm'] | td[@class='ml'] | td[@class='ol'] | td[@class='lt']">
  157. <Field name="head">
  158. <xsl:value-of select="span"/>
  159. </Field>
  160. </xsl:template>
  161. <xsl:template match="td[@class='mv'] | td[@class='ov'] | td[@class='lc'] | td[@class='lm']">
  162. <Field name="val">
  163. <xsl:value-of select="span"/>
  164. </Field>
  165. </xsl:template>
  166. <!-- Handle CMM responses -->
  167. <xsl:variable name="cmm-types" select="/root/metrics/MetricShortStats/table/row[2] | /root/metrics/ob_server/ob_response/table/types"/>
  168. <xsl:template match="MetricShortStats | ob_server/ob_response">
  169. <xsl:if test="string(image/row/uri) != ''">
  170. <xsl:for-each select="table/*">
  171. <xsl:choose>
  172. <xsl:when test="position()=1 or local-name()='columns'">
  173. <MODULE_RESULT resultCode="success">
  174. <xsl:for-each select="*">
  175. <Field name="head">
  176. <xsl:value-of select="."/>
  177. </Field>
  178. </xsl:for-each>
  179. </MODULE_RESULT>
  180. </xsl:when>
  181. <xsl:when test="position()=2 or local-name()='types'"/>
  182. <xsl:otherwise>
  183. <MODULE_RESULT resultCode="success">
  184. <xsl:for-each select="*">
  185. <xsl:variable name="pos" select="position()"/>
  186. <Field>
  187. <xsl:attribute name="name">
  188. <xsl:choose>
  189. <xsl:when test="$cmm-types/*[$pos] = 'image'">img</xsl:when>
  190. <xsl:otherwise>val</xsl:otherwise>
  191. </xsl:choose>
  192. </xsl:attribute>
  193. <xsl:value-of select="."/>
  194. </Field>
  195. </xsl:for-each>
  196. </MODULE_RESULT>
  197. </xsl:otherwise>
  198. </xsl:choose>
  199. </xsl:for-each>
  200. <xsl:apply-templates select="table/*"/>
  201. </xsl:if>
  202. </xsl:template>
  203. <!-- Handle burgundy search results -->
  204. <xsl:template match="burgundy">
  205. <xsl:apply-templates select="cs:document/cs:result/cs:searchResults/cs:items/cs:item"/>
  206. </xsl:template>
  207. <xsl:template match="cs:item">
  208. <MODULE_RESULT resultCode="success" cogType="{key('class-names', cs:type)}">
  209. <U>
  210. <xsl:choose>
  211. <xsl:when test="cs:itemType = 'CMM'">
  212. <xsl:value-of select="cs:url"/>
  213. </xsl:when>
  214. <xsl:otherwise>
  215. <xsl:value-of select="$gw"/>
  216. <xsl:text/>?b_action=xts.run&amp;m=onebox/launch.xts&amp;id=<xsl:value-of select="cs:id"/>
  217. </xsl:otherwise>
  218. </xsl:choose>
  219. </U>
  220. <Title><xsl:value-of select="cs:name"/></Title>
  221. <!-- TODO: fix this when burgundy doesn't return markup in the cs:detail anymore?
  222. <Field name="description">
  223. <xsl:value-of select="cs:matchDescription/cs:detail" disable-output-escaping="yes"/>
  224. </Field>
  225. -->
  226. </MODULE_RESULT>
  227. </xsl:template>
  228. <!-- Handle CM search results -->
  229. <xsl:template match="nav:searchResponse">
  230. <xsl:apply-templates select="nav:content/nav:item | nav:content/nav:container"/>
  231. </xsl:template>
  232. <xsl:template match="nav:item | nav:container">
  233. <MODULE_RESULT resultCode="success" cogType="{key('class-names', nav:type)}">
  234. <U><xsl:value-of select="nav:defaultAction/nav:url"/></U>
  235. <Title><xsl:value-of select="nav:name"/></Title>
  236. <Field name="description">
  237. <xsl:value-of select="nav:description"/>
  238. </Field>
  239. </MODULE_RESULT>
  240. </xsl:template>
  241. <xsl:template match="error">
  242. <MODULE_RESULT resultCode="lookupFailure">
  243. <Diagnostics>
  244. <xsl:value-of select="fault//messageString[1]"/>
  245. </Diagnostics>
  246. </MODULE_RESULT>
  247. </xsl:template>
  248. <xsl:template match="text()"/>
  249. </xsl:stylesheet>