messageasjs.xslt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:encode="java:com.cognos.portal.utils.EncodingUtils">
  13. <xsl:output method="text" version="1.0" encoding="UTF-8" indent="no"/>
  14. <xsl:param name="section"/>
  15. <xsl:variable name="sectionList" select="concat(',',$section,',')"/>
  16. <xsl:template match="/">
  17. <xsl:text>/*&#10; (C) Copyright IBM Corp. 2005, 2011.&#10; Licensed Material - Property of IBM Corp. IBM, the IBM logo, and Cognos are trademarks of IBM Corp., registered in many jurisdictions worldwide.&#10;*/&#10;</xsl:text>
  18. <xsl:apply-templates select="/stringTable/component"/>
  19. </xsl:template>
  20. <xsl:template match="component">
  21. <xsl:text>var </xsl:text>
  22. <xsl:value-of select="@name"/>
  23. <xsl:text> = {&#10;</xsl:text>
  24. <xsl:for-each select="section[string($section) = '' or contains($sectionList,concat(',',@name,','))]">
  25. <xsl:if test="position() != 1">
  26. <xsl:text>,&#10;</xsl:text>
  27. </xsl:if>
  28. <xsl:text>&#9;</xsl:text>
  29. <xsl:value-of select="@name"/>
  30. <xsl:text>: {&#10;</xsl:text>
  31. <xsl:apply-templates select="string"/>
  32. <xsl:text>&#10;&#9;}</xsl:text>
  33. </xsl:for-each>
  34. <xsl:text>,
  35. /**
  36. * formatString usage:
  37. * using param names in message string:
  38. * formatString(msg, "name1", "value1", "name2", "value2", ...)
  39. * using indexes in message string:
  40. * formatString(msg, ["value1", "value2", ...])
  41. */
  42. formatString: function(sourceString) {
  43. var result = sourceString;
  44. var i, l=arguments.length;
  45. if (l == 2 &amp;&amp; typeof arguments[1] == "object" &amp;&amp; arguments[1].length > 0) {
  46. // second argument is an array of values
  47. args = arguments[1];
  48. l = args.length;
  49. for (i = 0; i &lt; l; i++) {
  50. result = result.replace(new RegExp("\\^" + i + "\\^"), args[i])
  51. }
  52. } else {
  53. for (i = 1; (i + 1) &lt; l; i += 2) {
  54. result = result.replace(new RegExp("\\^" + arguments[i] + "\\^"), arguments[i + 1])
  55. }
  56. }
  57. return result;
  58. }
  59. };
  60. </xsl:text>
  61. </xsl:template>
  62. <xsl:template match="string">
  63. <xsl:if test="position() != 1">
  64. <xsl:text>,&#10;</xsl:text>
  65. </xsl:if>
  66. <xsl:text>&#9;&#9;</xsl:text>
  67. <xsl:choose>
  68. <xsl:when test="@id">
  69. <xsl:value-of select="@id"/>
  70. </xsl:when>
  71. <xsl:when test="@name">
  72. <xsl:value-of select="../../@name"/>
  73. <xsl:text>_</xsl:text>
  74. <xsl:value-of select="../@name"/>
  75. <xsl:text>_</xsl:text>
  76. <xsl:value-of select="@name"/>
  77. </xsl:when>
  78. <xsl:otherwise>
  79. <xsl:message terminate="yes">Key Generation Error: Missing name or id.</xsl:message>
  80. </xsl:otherwise>
  81. </xsl:choose>
  82. <xsl:text>: "</xsl:text>
  83. <xsl:if test="@errorCode and (not(../@type) or ../@type='Messages')">
  84. <xsl:value-of select="../../@name"/>
  85. <xsl:text>-</xsl:text>
  86. <xsl:value-of select="../@name"/>
  87. <xsl:text>-</xsl:text>
  88. <xsl:value-of select="@errorCode"/>
  89. <xsl:text>&#32;</xsl:text>
  90. </xsl:if>
  91. <xsl:apply-templates mode="string"/>
  92. <xsl:text>"</xsl:text>
  93. </xsl:template>
  94. <xsl:template match="text()" mode="string">
  95. <xsl:value-of select="encode:javascriptencode(.)"/>
  96. </xsl:template>
  97. <xsl:template match="param" mode="string">
  98. <xsl:choose>
  99. <xsl:when test="@name">
  100. <xsl:value-of select="concat('^', @name, '^')"/>
  101. </xsl:when>
  102. <xsl:when test="@index">
  103. <xsl:value-of select="concat('^', @index - 1, '^')"/>
  104. </xsl:when>
  105. <xsl:otherwise>
  106. <xsl:message terminate="yes">Parameter Substitution Error: Missing name or index.</xsl:message>
  107. </xsl:otherwise>
  108. </xsl:choose>
  109. </xsl:template>
  110. <xsl:template match="text()"/>
  111. </xsl:stylesheet>