CCLXmlToProperties.xslt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: localizationkit
  5. (C) Copyright IBM Corp. 2005, 2016
  6. US Government Users Restricted Rights - Use, duplication or disclosure restricted
  7. by GSA ADP Schedule Contract with IBM Corp.
  8. -->
  9. <!--
  10. Module: CCLXmlToProperties.xslt
  11. Purpose:
  12. Transforms a CCL Resource Input File into a Java Properties file, also insert proper prefix into strings
  13. in all Messages sections. The Java Properties file will be generated in the following format:
  14. <key> = <message text>
  15. Rules:
  16. 1) Each string must defined either or both "id" and "name" attributes, which will be used to generate the <key> identifier.
  17. When both are defined, "id" will takes precedence over "<comp-name>_<sect-name>_<name>".
  18. 2) For string in Messages section with "errorCode" defined, the following format will bs used as prefix:
  19. <component_name>-<section_name>-<errorCode>.
  20. 3) All CCL parameter substitution element (regardless whether defined in Messages section or not) will be converted
  21. into Java parameter substituion format using the {} syntax as follows:
  22. <param name="xxx"/> will be converted to {xxx}.
  23. <param index="<int>"/> will be converted to {<int>-1}.
  24. When both "name" and "index" attributes are defined, the "name" attribute will takes precedence.
  25. 4) To conform with xml specification, non-meaningful whitespaces will be trimmed, and meaningful whitespace must
  26. be kept. The following are some examples:
  27. Example 1:
  28. <string id="ID1">There are
  29. <param name="count"/> items.
  30. </string>
  31. Example 2:
  32. <string id="ID1">
  33. <param name="count"/> items.
  34. </string>
  35. Example 3:
  36. <string id="ID1">
  37. <param name="count"/> items.</string>
  38. All these examples will be transformed into
  39. ID1 = CPN-SEN-xxxx {count} items.
  40. Note: For readibility, linefeed and tab had been added.
  41. -->
  42. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  43. <xsl:output method="text" encoding="UTF-8"/>
  44. <xsl:template match="/stringTable">
  45. <!-- Generate Header and Copyright notice. -->
  46. <xsl:text>#&#x0a;</xsl:text>
  47. <xsl:text># Licensed Materials - Property of IBM &#x0a;</xsl:text>
  48. <xsl:text># IBM Cognos Products: localizationkit &#x0a;</xsl:text>
  49. <xsl:text># (C) Copyright IBM Corp. 2005, 2016&#x0a;</xsl:text>
  50. <xsl:text># US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.&#x0a;</xsl:text>
  51. <xsl:text>#&#x0a;</xsl:text>
  52. <xsl:text>&#x0a;</xsl:text>
  53. <xsl:text>## DO NOT EDIT! &#x0a;</xsl:text>
  54. <xsl:text>## Generated using CCLXmlToProperties.xslt &#x0a;</xsl:text>
  55. <xsl:text>## END OF WARNING &#x0a;</xsl:text><!--CAUTION: DQ team are using this line for processing indication.-->
  56. <xsl:for-each select="./component">
  57. <xsl:variable name="compname" select="@name"/>
  58. ##
  59. ## Component: <xsl:value-of select="@name"/>
  60. ##
  61. ## Description: <xsl:value-of select="@usage"/>
  62. ##<xsl:text>&#10;</xsl:text>
  63. <xsl:for-each select="./section">
  64. <xsl:variable name="sectname" select="@name"/>
  65. #
  66. # Section: <xsl:value-of select="@name"/>
  67. #
  68. # Description: <xsl:value-of select="@usage"/>
  69. #<xsl:text>&#10;</xsl:text>
  70. <xsl:for-each select="string">
  71. <!-- generate the key, use either "id" or "<comp-name>_<sect-name>_<name>" -->
  72. <xsl:choose>
  73. <xsl:when test="@id">
  74. <xsl:value-of select="@id"/>
  75. </xsl:when>
  76. <xsl:when test="@name">
  77. <xsl:value-of select="../../@name"/>
  78. <xsl:text disable-output-escaping="yes">_</xsl:text>
  79. <xsl:value-of select="../@name"/>
  80. <xsl:text disable-output-escaping="yes">_</xsl:text>
  81. <xsl:value-of select="@name"/>
  82. </xsl:when>
  83. <xsl:otherwise>
  84. <xsl:message terminate="yes">Key Generation Error: Missing name or id.</xsl:message>
  85. </xsl:otherwise>
  86. </xsl:choose>
  87. <!-- generate the key/value separator (make sure we put a space before the '=') -->
  88. <xsl:text disable-output-escaping="yes"> = </xsl:text>
  89. <!-- generate the prefix based on rule #2 -->
  90. <xsl:if test="@errorCode and (not(../@type) or ../@type='Messages')">
  91. <xsl:value-of select="../../@name"/>
  92. <xsl:text>-</xsl:text>
  93. <xsl:value-of select="../@name"/>
  94. <xsl:text>-</xsl:text>
  95. <xsl:value-of select="@errorCode"/>
  96. <xsl:text>&#32;</xsl:text>
  97. </xsl:if>
  98. <!-- generate the message text based on rule #3 and #4 -->
  99. <xsl:variable name="msgstring">
  100. <xsl:for-each select="child::node()">
  101. <xsl:choose>
  102. <xsl:when test="name() = 'param'">
  103. <xsl:choose>
  104. <xsl:when test="@name">
  105. <xsl:text disable-output-escaping="yes">{</xsl:text>
  106. <xsl:value-of select="@name"/>
  107. <xsl:text disable-output-escaping="yes">}</xsl:text>
  108. </xsl:when>
  109. <xsl:when test="@index">
  110. <xsl:text disable-output-escaping="yes">{</xsl:text>
  111. <xsl:value-of select="@index - 1"/>
  112. <xsl:text disable-output-escaping="yes">}</xsl:text>
  113. </xsl:when>
  114. <xsl:otherwise>
  115. <xsl:message terminate="yes">Parameter Substitution Error: Missing name or index.</xsl:message>
  116. </xsl:otherwise>
  117. </xsl:choose>
  118. </xsl:when>
  119. <xsl:when test="name() = ''">
  120. <xsl:value-of select="."/>
  121. </xsl:when>
  122. <xsl:otherwise>
  123. <xsl:apply-templates select="."/>
  124. </xsl:otherwise>
  125. </xsl:choose>
  126. </xsl:for-each>
  127. </xsl:variable>
  128. <xsl:choose>
  129. <xsl:when test="@whiteSpace and @whiteSpace='preserve'">
  130. <xsl:value-of disable-output-escaping="yes" select="$msgstring"/>
  131. </xsl:when>
  132. <xsl:otherwise>
  133. <xsl:value-of select="normalize-space($msgstring)"/>
  134. </xsl:otherwise>
  135. </xsl:choose>
  136. <xsl:text>&#10;</xsl:text>
  137. </xsl:for-each>
  138. </xsl:for-each>
  139. </xsl:for-each>
  140. </xsl:template>
  141. <!-- copy everything by default -->
  142. <xsl:template match="*">
  143. <xsl:copy>
  144. <xsl:copy-of select="@*"/>
  145. <xsl:apply-templates/>
  146. </xsl:copy>
  147. </xsl:template>
  148. </xsl:stylesheet>