123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- +========================================================================+
- | IBM Confidential
- | OCO Source Materials
- | IBM Cognos Products: BUX
- | (C) Copyright IBM Corp. 2009, 2012
- |
- | The source code for this program is not published or otherwise
- | divested of its trade secrets, irrespective of what has been deposited
- | with the U.S. Copyright Office.
- +========================================================================+
- -->
- <!--
- Module: CCLXmlToProperties.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>
- 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="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:output method="text" encoding="UTF-8"/>
- <xsl:template match="/stringTable">
- <xsl:text>/* </xsl:text>
- <xsl:text> *+------------------------------------------------------------------------+ </xsl:text>
- <xsl:text> *| IBM Confidential </xsl:text>
- <xsl:text> *| OCO Source Materials </xsl:text>
- <xsl:text> *| IBM Cognos Products: BUX </xsl:text>
- <xsl:text> *| (C) Copyright IBM Corp. 2009, 2012 </xsl:text>
- <xsl:text> *| </xsl:text>
- <xsl:text> *| The source code for this program is not published or otherwise </xsl:text>
- <xsl:text> *| divested of its trade secrets, irrespective of what has been deposited </xsl:text>
- <xsl:text> *| with the U.S. Copyright Office. </xsl:text>
- <xsl:text> *+------------------------------------------------------------------------+ </xsl:text>
- <xsl:text> */ </xsl:text>
- <xsl:text>({</xsl:text>
- <xsl:for-each select="./component">
- <xsl:variable name="compname" select="@name"/>
- <xsl:for-each select="section">
- <xsl:if test="preceding-sibling::section">
- <xsl:text>,</xsl:text>
- </xsl:if>
- <xsl:text> "</xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text>": { // </xsl:text>
- <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:if test="preceding-sibling::string">
- <xsl:text>, </xsl:text>
- </xsl:if>
- <xsl:variable name="var">
- <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>
- </xsl:variable>
- <xsl:text> "</xsl:text>
- <xsl:value-of select="translate($var, 'abcdefghijklmnopqrstuvwxyz .-', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ___')"/>
- <xsl:text>"</xsl:text>
- <!-- generate the key/value separator (make sure we put a space before the '=') -->
- <xsl:text>: "</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>
- <xsl:variable name="msgstring_param">
- <xsl:choose>
- <xsl:when test="@whiteSpace and @whiteSpace='preserve'">
- <xsl:value-of select="$msgstring"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="normalize-space($msgstring)"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <call-template name="replaceChar">
- <with-param name="text">
- <call-template name="replaceChar">
- <with-param name="text" select="$msgstring_param" />
- <with-param name="toReplace">\</with-param>
- <with-param name="replaceWith">\\</with-param>
- </call-template>
- </with-param>
- <with-param name="toReplace">"</with-param>
- <with-param name="replaceWith">\"</with-param>
- </call-template>
- <xsl:text>"</xsl:text>
- </xsl:for-each>
- <xsl:text> }</xsl:text>
- </xsl:for-each>
- </xsl:for-each>
- <xsl:text> })</xsl:text>
- </xsl:template>
- <xsl:template name="replaceChar">
- <xsl:param name="text" />
- <xsl:param name="toReplace" />
- <xsl:param name="replaceWith" />
- <xsl:choose>
- <xsl:when test="contains($text, $toReplace)">
- <xsl:variable name="beforeChar" select="substring-before($text,$toReplace)" />
- <xsl:variable name="afterChar">
- <xsl:call-template name="replaceChar">
- <xsl:with-param name="text" select="substring-after($text,$toReplace)" />
- <xsl:with-param name="toReplace" select="$toReplace" />
- <xsl:with-param name="replaceWith" select="$replaceWith" />
- </xsl:call-template>
- </xsl:variable>
- <xsl:value-of select="concat($beforeChar, $replaceWith, $afterChar)" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$text" />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!-- copy everything by default -->
- <xsl:template match="*">
- <xsl:copy>
- <xsl:copy-of select="@*"/>
- <xsl:apply-templates/>
- </xsl:copy>
- </xsl:template>
- </xsl:stylesheet>
|