localeSelector.xslt 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. <xsl:stylesheet version="1.0"
  13. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  14. xmlns:out="dummy-uri"
  15. xmlns:layout="http://developer.cognos.com/common/layout"
  16. exclude-result-prefixes="layout">
  17. <xsl:output method="xml" encoding="UTF-8" indent="no"/>
  18. <xsl:namespace-alias stylesheet-prefix="out" result-prefix="xsl"/>
  19. <xsl:template match="layout:localeselectorcontrol">
  20. <xsl:variable name="lscFormname">
  21. <xsl:choose>
  22. <xsl:when test="./layout:controlparameters/formname">
  23. <xsl:value-of select="./layout:controlparameters/formname"/></xsl:when>
  24. <xsl:when test="ancestor::layout:form/@name">
  25. <xsl:value-of select="ancestor::layout:form/@name"/>
  26. </xsl:when>
  27. <xsl:otherwise>pform</xsl:otherwise>
  28. </xsl:choose>
  29. </xsl:variable>
  30. <xsl:variable name="lscShortFormname">
  31. <xsl:choose>
  32. <xsl:when test="contains($lscFormname,'_THIS_')">
  33. <xsl:value-of select="substring-after($lscFormname,'_THIS_')"/>
  34. </xsl:when>
  35. <xsl:otherwise><xsl:value-of select="$lscFormname"/></xsl:otherwise>
  36. </xsl:choose>
  37. </xsl:variable>
  38. <xsl:variable name="lscSelectorname" select="@name"/>
  39. <xsl:variable name="lscExtendremovefunction">
  40. <xsl:if test="./layout:controlparameters/extendremovefunction"><xsl:value-of select="./layout:controlparameters/extendremovefunction"/></xsl:if>
  41. </xsl:variable>
  42. <out:variable name="useLscItemlist">
  43. <xsl:copy-of select="./layout:controlparameters/fieldlist"/><xsl:text>,</xsl:text>
  44. </out:variable>
  45. <out:variable name="useLscItemlistarray">
  46. <out:call-template name="createItemList">
  47. <out:with-param name="items"><out:value-of select="$useLscItemlist"/></out:with-param>
  48. </out:call-template>
  49. </out:variable>
  50. <out:variable name="useLscContentLocales">
  51. <xsl:choose>
  52. <xsl:when test="./layout:controlparameters/contentlocales"><xsl:copy-of select="./layout:controlparameters/contentlocales/*"/></xsl:when>
  53. <xsl:otherwise><out:copy-of select="/root/input[@name='configurationResponse']/config/param[@name='contentLocales']/*"/></xsl:otherwise>
  54. </xsl:choose>
  55. </out:variable>
  56. <out:variable name="useLscItemlistfirstitem"><out:value-of select="substring-before($useLscItemlist,',')"/></out:variable>
  57. <out:variable name="useLscCustoms">
  58. <xsl:choose>
  59. <xsl:when test="./layout:controlparameters/customs"><xsl:copy-of select="./layout:controlparameters/customs/*"/></xsl:when>
  60. <xsl:otherwise><out:copy-of select="/root/customs/param[@name=$useLscItemlistfirstitem]/*"/></xsl:otherwise>
  61. </xsl:choose>
  62. </out:variable>
  63. <out:variable name="useLscPreferences">
  64. <xsl:choose>
  65. <xsl:when test="./layout:controlparameters/preferences"><xsl:copy-of select="./layout:controlparameters/preferences/*"/></xsl:when>
  66. <xsl:otherwise><out:copy-of select="/root/preferences/param[@name='contentLocale']"/></xsl:otherwise>
  67. </xsl:choose>
  68. </out:variable>
  69. <out:variable name="useLscPreferencesLocale" select="$useLscPreferences/param[@name='contentLocale']"/>
  70. <out:variable name="useLscSelection">
  71. <out:choose>
  72. <out:when test="not($useLscCustoms/param[@name=$useLscItemlistfirstitem]/value)">
  73. <out:value-of select="$useLscPreferencesLocale"/>
  74. </out:when>
  75. <out:otherwise>
  76. <out:variable name="lscLangs">
  77. <out:for-each select="$useLscCustoms/param[@name=$useLscItemlistfirstitem]/value">
  78. <out:value-of select="@xml:lang"/>
  79. <out:if test="not(position() = last())">,</out:if>
  80. </out:for-each>
  81. </out:variable>
  82. <out:if test="$lscLangs != ''">
  83. <out:value-of select="java:getBestFitLocale(string($useLscPreferencesLocale),string($lscLangs))" xmlns:java="java:com.cognos.portal.utils.CCLLocaleUtils"/>
  84. </out:if>
  85. </out:otherwise>
  86. </out:choose>
  87. </out:variable>
  88. <layout:section format="select-locale">
  89. <xsl:apply-templates select="./*[not(name()='layout:fieldlist' or name()='layout:label')]"/>
  90. <xsl:call-template name="localeselectorFields"/>
  91. <layout:hidden name="LocaleSelect" value="{'{$useLscSelection}'}"/>
  92. <layout:hidden name="removeLang" value=""/>
  93. <layout:script>
  94. var _THIS_gArrRemovedLocale = new Array();
  95. var _THIS_itemList = new Array(<out:value-of select="$useLscItemlistarray"/>);
  96. </layout:script>
  97. <xsl:if test="./layout:label">
  98. <layout:label for="_THIS_{$lscSelectorname}">
  99. <xsl:copy-of select="./layout:label/*"/>
  100. </layout:label>
  101. </xsl:if>
  102. <layout:select id="_THIS_{$lscSelectorname}" class="cogstyle-render-selector" name="_THIS_{$lscSelectorname}">
  103. <xsl:attribute name="onchange">javascript:adjustSelection('_THIS_','<xsl:value-of select="$lscShortFormname"/>','<xsl:value-of select="$lscSelectorname"/>',_THIS_itemList,'create')</xsl:attribute>
  104. <out:choose>
  105. <out:when test="not($useLscCustoms/param[@name=$useLscItemlistfirstitem]/value)">
  106. <layout:option value="{'{$useLscSelection}'}" selected="selected">
  107. <out:value-of select="$useLscContentLocales/locale[@id=$useLscSelection]"/>
  108. </layout:option>
  109. </out:when>
  110. <out:otherwise>
  111. <out:variable name="localeList">
  112. <out:for-each select="$useLscCustoms/param[@name=$useLscItemlistfirstitem]/value">
  113. <out:variable name="vLang" select="@xml:lang"/>
  114. <locale id="{'{$vLang}'}"><out:value-of select="$useLscContentLocales/locale[@id=$vLang]"/></locale>
  115. </out:for-each>
  116. </out:variable>
  117. <out:for-each select="$localeList/locale">
  118. <out:sort select="."/>
  119. <layout:option value="{'{@id}'}" id="{'{.}'}">
  120. <out:if test="@id=$useLscSelection">
  121. <out:attribute name="selected">selected</out:attribute>
  122. </out:if>
  123. <out:value-of select="."/>
  124. </layout:option>
  125. </out:for-each>
  126. </out:otherwise>
  127. </out:choose>
  128. <layout:option value="-"><out:value-of select="'--------------------'"/></layout:option>
  129. <out:for-each select="$useLscContentLocales/locale">
  130. <out:variable name="cId" select="@id"/>
  131. <out:variable name="displayName" select="string(.)"/>
  132. <out:choose>
  133. <out:when test="not($useLscCustoms/param[@name=$useLscItemlistfirstitem]/value)">
  134. <out:if test="$cId != $useLscSelection">
  135. <layout:option value="{'{$cId}'}">
  136. <out:value-of select="$displayName"/>
  137. </layout:option>
  138. </out:if>
  139. </out:when>
  140. <out:otherwise>
  141. <out:if test="not($useLscCustoms/param[@name=$useLscItemlistfirstitem]/value/@xml:lang=$cId)">
  142. <layout:option value="{'{$cId}'}">
  143. <out:value-of select="$displayName"/>
  144. </layout:option>
  145. </out:if>
  146. </out:otherwise>
  147. </out:choose>
  148. </out:for-each>
  149. </layout:select>
  150. <layout:removelocaleaction>adjustSelection('_THIS_','<xsl:value-of select="$lscShortFormname"/>','<xsl:value-of select="$lscSelectorname"/>',_THIS_itemList,'remove');<xsl:value-of select="$lscExtendremovefunction"/></layout:removelocaleaction>
  151. </layout:section>
  152. </xsl:template>
  153. <xsl:template match="layout:label">
  154. <xsl:copy-of select="."/>
  155. </xsl:template>
  156. <xsl:template name="localeselectorFields">
  157. <out:for-each select="$useLscCustoms/param">
  158. <out:variable name="pname" select="@name"/>
  159. <out:if test="./value">
  160. <out:for-each select="./value">
  161. <layout:hidden>
  162. <out:attribute name="name"><out:value-of select="concat($pname,'-',string(@xml:lang))"/></out:attribute>
  163. <out:attribute name="value"><out:value-of select="string(.)"/></out:attribute>
  164. </layout:hidden>
  165. </out:for-each>
  166. </out:if>
  167. </out:for-each>
  168. </xsl:template>
  169. <xsl:template match="layout:selectortemplates">
  170. <out:template name="createItemList">
  171. <out:param name="items" select="''"/>
  172. <out:variable name="curritem" select="substring-before($items,',')"/>
  173. <out:variable name="nextitems" select="substring-after($items,',')"/>
  174. <out:value-of select="concat('&quot;',$curritem,'&quot;')"/>
  175. <out:if test="$nextitems!=''">
  176. <out:text/><xsl:value-of select="','"/><xsl:text/>
  177. <out:call-template name="createItemList">
  178. <out:with-param name="items" select="$nextitems"/>
  179. </out:call-template>
  180. </out:if>
  181. </out:template>
  182. </xsl:template>
  183. <xsl:template match="*">
  184. <xsl:copy>
  185. <xsl:copy-of select="@*"/>
  186. <xsl:apply-templates/>
  187. </xsl:copy>
  188. </xsl:template>
  189. </xsl:stylesheet>
  190. <!-- $Header: //cpscrn/main/src/java/etc/webapps/cps/WEB-INF/fragments/producers/utilities/common/logic/localeSelector.xslt#1 $ -->
  191. <!-- $DateTime: 2008/10/22 11:12:04 $ -->
  192. <!-- $Change: 25109 $ -->