RSUpgradeFormat.xsl 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: rspecupgrade
  5. (C) Copyright IBM Corp. 2005, 2010
  6. US Government Users Restricted Rights - Use, duplication or disclosure
  7. restricted by GSA ADP Schedule Contract with IBM Corp.
  8. -->
  9. <!-- COPYRIGHT_DATA { 'YEAR':[2005, 2009], 'RELEASE':['colorado_wave1'], 'VISIBLE':'YES', 'COMPONENT':'rspecupgrade' }-->
  10. <!--All lines above the COPYRIGHT_DATA line will be replaced when copyright notices are generated. -->
  11. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:baltic="http://developer.cognos.com/schemas/report/1/" xmlns:mlt="http://myLookupTable/" xmlns="http://developer.cognos.com/schemas/report/2.0/" xmlns:date="http://exslt.org/dates-and-times" xmlns:exsl="http://exslt.org/common" xmlns:xalan="http://xml.apache.org/xalan" xmlns:java="http://xml.apache.org/xalan/java" extension-element-prefixes="xalan date exsl" exclude-result-prefixes="xalan java baltic date exsl mlt">
  12. <!-- Start of dataFormat lookup table. -->
  13. <mlt:v4_dataFormat name="stringFormat"/>
  14. <mlt:v4_dataFormat name="numberFormat"/>
  15. <mlt:v4_dataFormat name="currencyFormat"/>
  16. <mlt:v4_dataFormat name="percentFormat"/>
  17. <mlt:v4_dataFormat name="dateFormat"/>
  18. <mlt:v4_dataFormat name="timeFormat"/>
  19. <mlt:v4_dataFormat name="dateTimeFormat"/>
  20. <mlt:v4_dataFormat name="intervalFormat"/>
  21. <mlt:v4_dataFormat name="format"/>
  22. <xsl:variable name="v_dataFormats" select="document('')/*/mlt:v4_dataFormat"/>
  23. <!-- End of dataFormat lookup table. -->
  24. <xsl:template name="formatGroupTemplate">
  25. <xsl:param name="p_recursive" select="'false'"/>
  26. <xsl:param name="p_includeDataFormatElement" select="'true'"/>
  27. <xsl:choose>
  28. <xsl:when test="$p_recursive = 'true'">
  29. <xsl:for-each select="../*[local-name()!='CSS']">
  30. <xsl:variable name="v_currentFormat" select="local-name(.)"/>
  31. <xsl:if test="count($v_dataFormats[@name=$v_currentFormat]) = 1">
  32. <xsl:choose>
  33. <xsl:when test="$p_includeDataFormatElement = 'true'">
  34. <dataFormat>
  35. <xsl:apply-templates select="."/>
  36. </dataFormat>
  37. </xsl:when>
  38. <xsl:otherwise>
  39. <xsl:apply-templates select="."/>
  40. </xsl:otherwise>
  41. </xsl:choose>
  42. </xsl:if>
  43. </xsl:for-each>
  44. </xsl:when>
  45. <xsl:otherwise>
  46. <xsl:for-each select="*[local-name()!='CSS']">
  47. <xsl:variable name="v_currentFormat" select="local-name(.)"/>
  48. <xsl:if test="count($v_dataFormats[@name=$v_currentFormat]) = 1">
  49. <xsl:choose>
  50. <xsl:when test="$p_includeDataFormatElement = 'true'">
  51. <dataFormat>
  52. <xsl:apply-templates select="."/>
  53. </dataFormat>
  54. </xsl:when>
  55. <xsl:otherwise>
  56. <xsl:apply-templates select="."/>
  57. </xsl:otherwise>
  58. </xsl:choose>
  59. </xsl:if>
  60. </xsl:for-each>
  61. </xsl:otherwise>
  62. </xsl:choose>
  63. </xsl:template>
  64. <xsl:template match="baltic:stringFormat">
  65. <stringFormat>
  66. <xsl:call-template name="copyFormatAttributesTemplate"/>
  67. </stringFormat>
  68. </xsl:template>
  69. <xsl:template match="baltic:numberFormat">
  70. <numberFormat>
  71. <xsl:call-template name="copyFormatAttributesTemplate"/>
  72. </numberFormat>
  73. </xsl:template>
  74. <xsl:template match="baltic:currencyFormat">
  75. <currencyFormat>
  76. <xsl:call-template name="copyFormatAttributesTemplate"/>
  77. </currencyFormat>
  78. </xsl:template>
  79. <xsl:template match="baltic:percentFormat">
  80. <percentFormat>
  81. <xsl:for-each select="attribute::*">
  82. <xsl:if test="name(.) != 'xml:lang'">
  83. <!-- Do not copy xml:lang attributes -->
  84. <xsl:if test="local-name(.) = 'scale' and . != '%'">
  85. <!-- Do not copy scale="%" attributes -->
  86. <xsl:copy/>
  87. </xsl:if>
  88. <xsl:if test="local-name(.) != 'scale'">
  89. <!-- Copy all other attributes -->
  90. <xsl:choose>
  91. <xsl:when test="local-name(.) = 'percentScale'">
  92. <xsl:if test=". &gt;= 0">
  93. <!-- negate positive percentScale drop negative scales -->
  94. <xsl:attribute name="percentScale"><xsl:value-of select="0 - ."/></xsl:attribute>
  95. </xsl:if>
  96. </xsl:when>
  97. <xsl:otherwise>
  98. <xsl:copy/>
  99. </xsl:otherwise>
  100. </xsl:choose>
  101. </xsl:if>
  102. </xsl:if>
  103. </xsl:for-each>
  104. </percentFormat>
  105. </xsl:template>
  106. <xsl:template match="baltic:dateFormat">
  107. <dateFormat>
  108. <xsl:call-template name="copyFormatAttributesTemplate"/>
  109. </dateFormat>
  110. </xsl:template>
  111. <xsl:template match="baltic:timeFormat">
  112. <timeFormat>
  113. <xsl:call-template name="copyFormatAttributesTemplate"/>
  114. </timeFormat>
  115. </xsl:template>
  116. <xsl:template match="baltic:dateTimeFormat">
  117. <dateTimeFormat>
  118. <xsl:call-template name="copyFormatAttributesTemplate"/>
  119. </dateTimeFormat>
  120. </xsl:template>
  121. <xsl:template match="baltic:intervalFormat">
  122. <intervalFormat>
  123. <xsl:call-template name="copyFormatAttributesTemplate"/>
  124. </intervalFormat>
  125. </xsl:template>
  126. <xsl:template match="baltic:format">
  127. <format>
  128. <xsl:call-template name="copyFormatAttributesTemplate"/>
  129. </format>
  130. </xsl:template>
  131. <xsl:template name="copyFormatAttributesTemplate">
  132. <xsl:for-each select="attribute::*">
  133. <xsl:if test="name(.) != 'xml:lang'">
  134. <!-- Do not copy xml:lang attributes -->
  135. <xsl:copy/>
  136. </xsl:if>
  137. </xsl:for-each>
  138. </xsl:template>
  139. </xsl:stylesheet>