getServiceDescription.xslt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: 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. <!-- $Header: //cpscrn/main/templates/cps4/producer/wsrp-impl/transforms/getServiceDescription.xslt#1 $ -->
  13. <!-- $DateTime: 2008/10/22 11:12:04 $ -->
  14. <!-- $Change: 25109 $ -->
  15. <xsl:stylesheet version="1.0"
  16. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  17. xmlns:wsrp="urn:oasis:names:tc:wsrp:v1:types"
  18. xmlns:exslt="http://exslt.org/sets"
  19. xmlns:xts="http://developer.cognos.com/schemas/xts/"
  20. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  21. exclude-result-prefixes="exslt xts">
  22. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  23. <!-- NOTES: -->
  24. <!-- * Product locales is used for offerred portlets supported languages and metadata (except title, shortTitle and description) -->
  25. <!-- * Content locales is used for Metadata descriptions (i.e. title, shortTitle and description) -->
  26. <xsl:variable name="locale">en</xsl:variable>
  27. <xsl:variable name="locales" select="/root/locale"/>
  28. <xsl:variable name="product-locales" select="/root/configuration/property[@name='productLocales']/locale"/>
  29. <xsl:variable name="content-locales" select="/root/configuration/property[@name='contentLocales']/locale"/>
  30. <xsl:variable name="product-locales-res" select="$product-locales[(id = $locales) and (id != $locale)]"/>
  31. <xsl:variable name="content-locales-res" select="$content-locales[(id = $locales) and (id != $locale)]"/>
  32. <xsl:variable name="locale-path" select="concat(substring-before(/root/message, '.xml'), '_', $locale, '.xml')"/>
  33. <xsl:variable name="locale-pathRL" select="concat(substring-before(/root/message, '.xml'), 'RL_', $locale, '.xml')"/>
  34. <xsl:variable name="locale-strings">
  35. <xsl:if test="xtsext:resourceExists($locale-path)='true'">
  36. <xsl:copy-of select="document($locale-path)//string"/>
  37. </xsl:if>
  38. <xsl:if test="xtsext:resourceExists($locale-pathRL)='true'">
  39. <xsl:copy-of select="document($locale-pathRL)//string"/>
  40. </xsl:if>
  41. </xsl:variable>
  42. <xsl:template match="/">
  43. <xsl:apply-templates select="/root/implementation | /root/portlet"/>
  44. </xsl:template>
  45. <xsl:template match="implementation">
  46. <wsrp:getServiceDescriptionResponse xmlns:wsrp="urn:oasis:names:tc:wsrp:v1:types" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  47. <wsrp:requiresRegistration>true</wsrp:requiresRegistration>
  48. <xsl:for-each select="portlet">
  49. <wsrp:offeredPortlets>
  50. <xsl:call-template name="gen-portlet"/>
  51. </wsrp:offeredPortlets>
  52. </xsl:for-each>
  53. <xsl:for-each select="./custom-windowstate">
  54. <wsrp:customWindowStateDescriptions itemName="{ @name }">
  55. <xsl:call-template name="value">
  56. <xsl:with-param name="tag" select="'description'"/>
  57. </xsl:call-template>
  58. </wsrp:customWindowStateDescriptions>
  59. </xsl:for-each>
  60. <xsl:for-each select="./custom-mode">
  61. <wsrp:customModeDescriptions itemName="{ @name }">
  62. <xsl:call-template name="value">
  63. <xsl:with-param name="tag" select="'description'"/>
  64. </xsl:call-template>
  65. </wsrp:customModeDescriptions>
  66. </xsl:for-each>
  67. <wsrp:requiresInitCookie>
  68. <xsl:value-of select="./@requiresInitCookie"/>
  69. </wsrp:requiresInitCookie>
  70. <xsl:if test="./property-description">
  71. <wsrp:registrationPropertyDescription xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  72. <xsl:for-each select="./property-description[not(@shared)]">
  73. <wsrp:propertyDescriptions name="{ @name }" type="{ @type }">
  74. <xsl:for-each select="label[1]">
  75. <xsl:call-template name="value">
  76. <xsl:with-param name="tag" select="'label'"/>
  77. </xsl:call-template>
  78. </xsl:for-each>
  79. <xsl:for-each select="hint[1]">
  80. <xsl:call-template name="value">
  81. <xsl:with-param name="tag" select="'hint'"/>
  82. </xsl:call-template>
  83. </xsl:for-each>
  84. <xsl:if test="default">
  85. <wsrp:extensions>
  86. <cpsext:defaultValue xmlns:cpsext="http://developer.cognos.com/schemas/cps/wsrp/extensions/1/">
  87. <xsl:value-of select="default"/>
  88. </cpsext:defaultValue>
  89. </wsrp:extensions>
  90. </xsl:if>
  91. <xsl:if test="values">
  92. <wsrp:extensions>
  93. <cpsext:values xmlns:cpsext="http://developer.cognos.com/schemas/cps/wsrp/extensions/1/">
  94. <xsl:for-each select="values/value">
  95. <cpsext:value name="{ @name }">
  96. <xsl:choose>
  97. <xsl:when test="@resourceID">
  98. <xsl:attribute name="xml:lang">
  99. <xsl:value-of select="$locale"/>
  100. </xsl:attribute>
  101. <xsl:attribute name="resourceName"><xsl:value-of select="@resourceID"/></xsl:attribute>
  102. <xsl:value-of select="$locale-strings/string[@id = current()/@resourceID]"/>
  103. </xsl:when>
  104. <xsl:otherwise>
  105. <xsl:attribute name="xml:lang">
  106. <xsl:value-of select="$locale"/>
  107. </xsl:attribute>
  108. <xsl:value-of select="."/>
  109. </xsl:otherwise>
  110. </xsl:choose>
  111. </cpsext:value>
  112. </xsl:for-each>
  113. </cpsext:values>
  114. </wsrp:extensions>
  115. </xsl:if>
  116. </wsrp:propertyDescriptions>
  117. </xsl:for-each>
  118. </wsrp:registrationPropertyDescription>
  119. </xsl:if>
  120. <xsl:if test="not($locales)">
  121. <xsl:for-each select="$content-locales">
  122. <xsl:sort select="id"/>
  123. <wsrp:locales>
  124. <xsl:value-of select="id"/>
  125. </wsrp:locales>
  126. </xsl:for-each>
  127. </xsl:if>
  128. <xsl:if test="$product-locales-res | $content-locales-res">
  129. <xsl:call-template name="gen-resources">
  130. <xsl:with-param name="resources" select="exslt:distinct( *[not(@shared='true')]/@resourceID | portlet/*/@resourceID | property-description[not(@shared='true')]//*/@resourceID )"/>
  131. </xsl:call-template>
  132. </xsl:if>
  133. </wsrp:getServiceDescriptionResponse>
  134. </xsl:template>
  135. <xsl:template match="portlet">
  136. <wsrp:getPortletDescriptionResponse xmlns:wsrp="urn:oasis:names:tc:wsrp:v1:types">
  137. <wsrp:portletDecription>
  138. <xsl:call-template name="gen-portlet"/>
  139. </wsrp:portletDecription>
  140. <xsl:call-template name="gen-resources">
  141. <xsl:with-param name="resources" select="exslt:distinct( .//*/@resourceID )"/>
  142. </xsl:call-template>
  143. </wsrp:getPortletDescriptionResponse>
  144. </xsl:template>
  145. <xsl:template name="gen-portlet">
  146. <wsrp:portletHandle><xsl:value-of select="@handle"/></wsrp:portletHandle>
  147. <wsrp:markupTypes>
  148. <xsl:for-each select="mimeType">
  149. <wsrp:mimeType>
  150. <xsl:value-of select="."/>
  151. </wsrp:mimeType>
  152. </xsl:for-each>
  153. <xsl:for-each select="mode">
  154. <wsrp:modes>
  155. <xsl:value-of select="."/>
  156. </wsrp:modes>
  157. </xsl:for-each>
  158. <xsl:for-each select="windowState">
  159. <wsrp:windowStates>
  160. <xsl:value-of select="."/>
  161. </wsrp:windowStates>
  162. </xsl:for-each>
  163. <xsl:choose>
  164. <!-- implementation.xml can tell us which locales are available -->
  165. <xsl:when test="locale">
  166. <xsl:for-each select="locale">
  167. <wsrp:locales>
  168. <xsl:value-of select="."/>
  169. </wsrp:locales>
  170. </xsl:for-each>
  171. </xsl:when>
  172. <!-- inside ReportNet, we use all available product locales -->
  173. <xsl:when test="$product-locales">
  174. <xsl:for-each select="$product-locales">
  175. <wsrp:locales>
  176. <xsl:value-of select="id"/>
  177. </wsrp:locales>
  178. </xsl:for-each>
  179. </xsl:when>
  180. <!-- only English is available -->
  181. <xsl:otherwise>
  182. <wsrp:locales>en</wsrp:locales>
  183. </xsl:otherwise>
  184. </xsl:choose>
  185. </wsrp:markupTypes>
  186. <wsrp:groupID><xsl:value-of select="@groupID"/></wsrp:groupID>
  187. <xsl:for-each select="description[1]">
  188. <xsl:call-template name="value">
  189. <xsl:with-param name="tag" select="'description'"/>
  190. </xsl:call-template>
  191. </xsl:for-each>
  192. <xsl:for-each select="shortTitle[1]">
  193. <xsl:call-template name="value">
  194. <xsl:with-param name="tag" select="'shortTitle'"/>
  195. </xsl:call-template>
  196. </xsl:for-each>
  197. <xsl:for-each select="title[1]">
  198. <xsl:call-template name="value">
  199. <xsl:with-param name="tag" select="'title'"/>
  200. </xsl:call-template>
  201. </xsl:for-each>
  202. <wsrp:usesMethodGet>false</wsrp:usesMethodGet>
  203. <wsrp:defaultMarkupSecure>false</wsrp:defaultMarkupSecure>
  204. <wsrp:onlySecure>false</wsrp:onlySecure>
  205. <wsrp:userContextStoredInSession>false</wsrp:userContextStoredInSession>
  206. <wsrp:templatesStoredInSession>false</wsrp:templatesStoredInSession>
  207. <wsrp:hasUserSpecificState>true</wsrp:hasUserSpecificState>
  208. <wsrp:doesUrlTemplateProcessing>false</wsrp:doesUrlTemplateProcessing>
  209. <xsl:if test="requiredCapabilities">
  210. <wsrp:extensions>
  211. <cpsext:meta xmlns:cpsext="http://developer.cognos.com/schemas/cps/wsrp/extensions/1/">
  212. <cpsext:requiredCapabilities>
  213. <xsl:value-of select="requiredCapabilities"/>
  214. </cpsext:requiredCapabilities>
  215. </cpsext:meta>
  216. </wsrp:extensions>
  217. </xsl:if>
  218. </xsl:template>
  219. <xsl:template name="gen-resources">
  220. <xsl:param name="resources"/>
  221. <xsl:if test="$resources">
  222. <wsrp:resourceList>
  223. <xsl:variable name="strings">
  224. <xsl:for-each select="exslt:distinct($product-locales-res/id | $content-locales-res/id)">
  225. <xsl:variable name="locale-res" select="."/>
  226. <xsl:variable name="path" select="concat(substring-before(/root/message, '.xml'), '_', $locale-res, '.xml')"/>
  227. <xsl:variable name="pathRL" select="concat(substring-before(/root/message, '.xml'), 'RL_', $locale-res, '.xml')"/>
  228. <xsl:choose>
  229. <xsl:when test="$product-locales-res[id = $locale-res] and $content-locales-res[id = $locale-res] and xtsext:resourceExists($path) and xtsext:resourceExists($pathRL)">
  230. <xsl:variable name="docs" select="document($path) | document($pathRL)"/>
  231. <xsl:if test="$docs/*">
  232. <locale id="{ $locale-res }">
  233. <xsl:copy-of select="$docs//string[@id = $resources]"/>
  234. </locale>
  235. </xsl:if>
  236. </xsl:when>
  237. <xsl:when test="$content-locales-res[id = $locale-res] and xtsext:resourceExists($pathRL)">
  238. <xsl:variable name="docs" select="document($pathRL)"/>
  239. <xsl:if test="$docs/*">
  240. <locale id="{ $locale-res }">
  241. <xsl:copy-of select="$docs//string[@id = $resources]"/>
  242. </locale>
  243. </xsl:if>
  244. </xsl:when>
  245. <xsl:when test="xtsext:resourceExists($path)">
  246. <xsl:variable name="docs" select="document($path)"/>
  247. <xsl:if test="$docs/*">
  248. <locale id="{ $locale-res }">
  249. <xsl:copy-of select="$docs//string[@id = $resources]"/>
  250. </locale>
  251. </xsl:if>
  252. </xsl:when>
  253. </xsl:choose>
  254. </xsl:for-each>
  255. </xsl:variable>
  256. <xsl:for-each select="$resources">
  257. <xsl:variable name="resource-id" select="."/>
  258. <xsl:if test="$strings/locale/string[@id = $resource-id]">
  259. <wsrp:resources resourceName="{ $resource-id }">
  260. <xsl:for-each select="$strings/locale[string[@id = $resource-id]]">
  261. <wsrp:values xml:lang="{ @id }">
  262. <wsrp:value>
  263. <xsl:value-of select="string[@id = $resource-id]"/>
  264. </wsrp:value>
  265. </wsrp:values>
  266. </xsl:for-each>
  267. </wsrp:resources>
  268. </xsl:if>
  269. </xsl:for-each>
  270. </wsrp:resourceList>
  271. </xsl:if>
  272. </xsl:template>
  273. <xsl:template name="value">
  274. <xsl:param name="tag"/>
  275. <xsl:choose>
  276. <xsl:when test="@resourceID">
  277. <xsl:element name="wsrp:{ $tag }" namespace="urn:oasis:names:tc:wsrp:v1:types">
  278. <xsl:attribute name="xml:lang">
  279. <xsl:value-of select="$locale"/>
  280. </xsl:attribute>
  281. <xsl:attribute name="resourceName"><xsl:value-of select="@resourceID"/></xsl:attribute>
  282. <wsrp:value>
  283. <xsl:value-of select="$locale-strings/string[@id = current()/@resourceID]"/>
  284. </wsrp:value>
  285. </xsl:element>
  286. </xsl:when>
  287. <xsl:otherwise>
  288. <xsl:element name="wsrp:{ $tag }" namespace="urn:oasis:names:tc:wsrp:v1:types">
  289. <xsl:attribute name="xml:lang">
  290. <xsl:value-of select="$locale"/>
  291. </xsl:attribute>
  292. <wsrp:value>
  293. <xsl:value-of select="."/>
  294. </wsrp:value>
  295. </xsl:element>
  296. </xsl:otherwise>
  297. </xsl:choose>
  298. </xsl:template>
  299. </xsl:stylesheet>