123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- Licensed Materials - Property of IBM
- IBM Cognos Products: localizationkit
- (C) Copyright IBM Corp. 2005, 2016
- US Government Users Restricted Rights - Use, duplication or disclosure restricted
- by GSA ADP Schedule Contract with IBM Corp.
- -->
- <!--
- Module: CCLXmlToProperties2.xslt
-
- Purpose:
- Transforms a CCL Resource Input File into a Java Properties file, also insert proper prefix into strings
- in all Messages sections. The Java Properties file will be generated in the following format:
- <key> = <message text>
-
- The ONLY difference between CCLXmlToProperties.xslt and CCLXmlToProperties2.xslt is the escaping of
- single quotes in the generated message. This is a requirement when using the Java MessageFormat
- class; otherwise a single quote is treated as a special escape to ignore parameter subsitution markers.
-
- Rules:
- 1) Each string must defined either or both "id" and "name" attributes, which will be used to generate the <key> identifier.
- When both are defined, "id" will takes precedence over "<comp-name>_<sect-name>_<name>".
- 2) For string in Messages section with "errorCode" defined, the following format will bs used as prefix:
- <component_name>-<section_name>-<errorCode>.
- 3) All CCL parameter substitution element (regardless whether defined in Messages section or not) will be converted
- into Java parameter substituion format using the {} syntax as follows:
- <param name="xxx"/> will be converted to {xxx}.
- <param index="<int>"/> will be converted to {<int>-1}.
- When both "name" and "index" attributes are defined, the "name" attribute will takes precedence.
- 4) To conform with xml specification, non-meaningful whitespaces will be trimmed, and meaningful whitespace must
- be kept. The following are some examples:
- Example 1:
- <string id="ID1">There are
- <param name="count"/> items.
- </string>
- Example 2:
- <string id="ID1">
- <param name="count"/> items.
- </string>
- Example 3:
- <string id="ID1">
- <param name="count"/> items.</string>
- All these examples will be transformed into
- ID1 = CPN-SEN-xxxx {count} items.
- Note: For readibility, linefeed and tab had been added.
- -->
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:output method="text" encoding="UTF-8"/>
- <xsl:variable name="singleQuote">
- <xsl:text>'</xsl:text>
- </xsl:variable>
- <xsl:variable name="doubleSingleQuote">
- <xsl:text>''</xsl:text>
- </xsl:variable>
- <xsl:template match="/stringTable">
- <!-- Generate Header and Copyright notice. -->
- <xsl:text>#
</xsl:text>
- <xsl:text># Licensed Materials - Property of IBM 
</xsl:text>
- <xsl:text># IBM Cognos Products: localizationkit 
</xsl:text>
- <xsl:text># (C) Copyright IBM Corp. 2005, 2016
</xsl:text>
- <xsl:text># US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
</xsl:text>
- <xsl:text>#
</xsl:text>
- <xsl:text>
</xsl:text>
- <xsl:text>## DO NOT EDIT! 
</xsl:text>
- <xsl:text>## Generated using CCLXmlToProperties2.xslt 
</xsl:text>
- <xsl:text>## END OF WARNING 
</xsl:text><!--CAUTION: Some components may use this line for processing indication.-->
- <xsl:for-each select="./component">
- <xsl:variable name="compname" select="@name"/>
- ##
- ## Component: <xsl:value-of select="@name"/>
- ##
- ## Description: <xsl:value-of select="@usage"/>
- ##<xsl:text> </xsl:text>
- <xsl:for-each select="./section">
- <xsl:variable name="sectname" select="@name"/>
- #
- # Section: <xsl:value-of select="@name"/>
- #
- # Description: <xsl:value-of select="@usage"/>
- #<xsl:text> </xsl:text>
- <xsl:for-each select="string">
- <!-- generate the key, use either "id" or "<comp-name>_<sect-name>_<name>" -->
- <xsl:choose>
- <xsl:when test="@id">
- <xsl:value-of select="@id"/>
- </xsl:when>
- <xsl:when test="@name">
- <xsl:value-of select="../../@name"/>
- <xsl:text disable-output-escaping="yes">_</xsl:text>
- <xsl:value-of select="../@name"/>
- <xsl:text disable-output-escaping="yes">_</xsl:text>
- <xsl:value-of select="@name"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:message terminate="yes">Key Generation Error: Missing name or id.</xsl:message>
- </xsl:otherwise>
- </xsl:choose>
- <!-- generate the key/value separator (make sure we put a space before the '=') -->
- <xsl:text disable-output-escaping="yes"> = </xsl:text>
- <!-- generate the prefix based on rule #2 -->
- <xsl:if test="@errorCode and (not(../@type) or ../@type='Messages')">
- <xsl:value-of select="../../@name"/>
- <xsl:text>-</xsl:text>
- <xsl:value-of select="../@name"/>
- <xsl:text>-</xsl:text>
- <xsl:value-of select="@errorCode"/>
- <xsl:text> </xsl:text>
- </xsl:if>
- <!-- generate the message text based on rule #3 and #4 -->
- <xsl:variable name="msgstring">
- <xsl:for-each select="child::node()">
- <xsl:choose>
- <xsl:when test="name() = 'param'">
- <xsl:choose>
- <xsl:when test="@name">
- <xsl:text disable-output-escaping="yes">{</xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text disable-output-escaping="yes">}</xsl:text>
- </xsl:when>
- <xsl:when test="@index">
- <xsl:text disable-output-escaping="yes">{</xsl:text>
- <xsl:value-of select="@index - 1"/>
- <xsl:text disable-output-escaping="yes">}</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:message terminate="yes">Parameter Substitution Error: Missing name or index.</xsl:message>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:when test="name() = ''">
- <xsl:value-of select="."/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates select="."/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- </xsl:variable>
- <!-- Escape single quotes, creating msgstring2 -->
- <xsl:variable name="msgstring2">
- <xsl:call-template name="DoReplace">
- <xsl:with-param name="text" select="$msgstring"/>
- <xsl:with-param name="replace" select="$singleQuote"/>
- <xsl:with-param name="by" select="$doubleSingleQuote"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="@whiteSpace and @whiteSpace='preserve'">
- <xsl:text disable-output-escaping="yes">\</xsl:text>
- <xsl:value-of select="$msgstring2"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="normalize-space($msgstring2)"/>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:text> </xsl:text>
- </xsl:for-each>
- </xsl:for-each>
- </xsl:for-each>
- </xsl:template>
- <!-- copy everything by default -->
- <xsl:template match="*">
- <xsl:copy>
- <xsl:copy-of select="@*"/>
- <xsl:apply-templates/>
- </xsl:copy>
- </xsl:template>
- <!-- DoReplace method for escaping single quotes in the message text -->
- <xsl:template name="DoReplace">
- <xsl:param name="text"/>
- <xsl:param name="replace"/>
- <xsl:param name="by"/>
- <xsl:choose>
- <xsl:when test="contains( $text, $replace )">
- <xsl:value-of select="substring-before( $text, $replace )"/>
- <xsl:value-of select="$by"/>
- <xsl:call-template name="DoReplace">
- <xsl:with-param name="text" select="substring-after( $text, $replace )"/>
- <xsl:with-param name="replace" select="$replace"/>
- <xsl:with-param name="by" select="$by"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$text"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- </xsl:stylesheet>
|