assembleSelectionSpec.xslt 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: ASV
  5. (C) Copyright IBM Corp. 2005, 2010
  6. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. -->
  8. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:bus="http://developer.cognos.com/schemas/bibus/3/" exclude-result-prefixes="bus">
  9. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  10. <!-- -->
  11. <xsl:template match="/root">
  12. <selection>
  13. <!-- tag the version of the additions to the selection spec - it might change in future -->
  14. <version>2.0</version>
  15. <!-- save the type of the threshold -->
  16. <type>
  17. <xsl:choose>
  18. <xsl:when test="not(/root/env/param[@name='m_sub_type'])">
  19. <xsl:text>nonMetric</xsl:text>
  20. </xsl:when>
  21. <xsl:otherwise>
  22. <xsl:value-of select="/root/env/param[@name='m_sub_type']"/>
  23. </xsl:otherwise>
  24. </xsl:choose>
  25. </type>
  26. <xsl:choose>
  27. <xsl:when test="/root/env/param[@name='m_sub_type'] = 'metric' ">
  28. <xsl:for-each select="/root/env/param[starts-with(@name, 'm_sub_perfPattern')]">
  29. <xsl:element name="{substring-after(string(@name),'m_sub_')}">
  30. <xsl:value-of select="."/>
  31. </xsl:element>
  32. </xsl:for-each>
  33. <xsl:for-each select="/selection/*[starts-with(local-name(),'perfPattern')]">
  34. <xsl:if test="not(/root/env/param[@name=concat('m_sub_',local-name())])">
  35. <xsl:copy-of select="."/>
  36. </xsl:if>
  37. </xsl:for-each>
  38. </xsl:when>
  39. <xsl:otherwise>
  40. <!-- set the measure value -->
  41. <measure_value>
  42. <xsl:choose>
  43. <!-- we have a value from the environment -->
  44. <xsl:when test="/root/env/param[@name='m_sub_measure_value'] and /root/env/param[@name='m_sub_measure_value']!='' ">
  45. <xsl:value-of select="/root/env/param[@name='m_sub_measure_value']"/>
  46. </xsl:when>
  47. <!-- we have a value already there -->
  48. <xsl:when test="/root/selection/measure_value and /root/selection/measure_value !='' ">
  49. <xsl:value-of select="/root/selection/measure_value"/>
  50. </xsl:when>
  51. <!-- we have a default value from the selection spec itself -->
  52. <xsl:otherwise>
  53. <xsl:value-of select="/root/selection/selections/query/selection/measures/measure/item/bus:value/item/bus:use"/>
  54. </xsl:otherwise>
  55. </xsl:choose>
  56. </measure_value>
  57. <!-- measure value1 has to always be there - it's initialized with the default value just incase the between operator is selected -->
  58. <measure_value1>
  59. <xsl:choose>
  60. <!-- we have a value from the environment -->
  61. <xsl:when test="/root/env/param[@name='m_sub_measure_value1'] and /root/env/param[@name='m_sub_measure_value1']!='' ">
  62. <xsl:value-of select="/root/env/param[@name='m_sub_measure_value1']"/>
  63. </xsl:when>
  64. <!-- we have a value already there -->
  65. <xsl:when test="/root/selection/measure_value1 and /root/selection/measure_value1 !='' ">
  66. <xsl:value-of select="/root/selection/measure_value1"/>
  67. </xsl:when>
  68. <!-- we have a default value from the selection spec itself -->
  69. <xsl:otherwise>
  70. <xsl:value-of select="/root/selection/selections/query/selection/measures/measure/item/bus:value/item/bus:use"/>
  71. </xsl:otherwise>
  72. </xsl:choose>
  73. </measure_value1>
  74. <xsl:variable name="dtype">
  75. <xsl:value-of select="/root/selection/selections/query/selection/measures/measure/@dtype"/>
  76. </xsl:variable>
  77. <operation>
  78. <xsl:choose>
  79. <!-- we have a value from the environment -->
  80. <xsl:when test="/root/env/param[@name='m_sub_operation'] and /root/env/param[@name='m_sub_operation']!='' ">
  81. <xsl:value-of select="/root/env/param[@name='m_sub_operation']"/>
  82. </xsl:when>
  83. <!-- we have a value there already -->
  84. <xsl:when test="/root/selection/operation and /root/selection/operation != '' ">
  85. <xsl:value-of select="/root/selection/operation"/>
  86. </xsl:when>
  87. <!-- default the value -->
  88. <xsl:when test="$dtype='25' or $dtype='26' or $dtype='27' or $dtype='28' or $dtype='29' or $dtype='30' or $dtype='31' or $dtype='32' or $dtype='34' or $dtype='35' or $dtype='36' or $dtype='43' or $dtype='45' or dtype='55' or $dtype='56'">
  89. <xsl:text>contains</xsl:text>
  90. </xsl:when>
  91. <xsl:otherwise>
  92. <xsl:text>greater_than</xsl:text>
  93. </xsl:otherwise>
  94. </xsl:choose>
  95. </operation>
  96. <!-- need other values depending on if we have between there or not -->
  97. <xsl:if test="/root/env/param[@name='m_sub_operation'] and /root/env/param[@name='m_sub_operation']='between' ">
  98. <measure_value_inclusive>
  99. <xsl:choose>
  100. <xsl:when test="/root/env/param[@name='m_sub_measure_value_inclusive']">
  101. <xsl:value-of select="/root/env/param[@name='m_sub_measure_value_inclusive']"/>
  102. </xsl:when>
  103. <xsl:otherwise>
  104. <xsl:text>false</xsl:text>
  105. </xsl:otherwise>
  106. </xsl:choose>
  107. </measure_value_inclusive>
  108. <measure_value_inclusive1>
  109. <xsl:choose>
  110. <xsl:when test="/root/env/param[@name='m_sub_measure_value_inclusive1']">
  111. <xsl:value-of select="/root/env/param[@name='m_sub_measure_value_inclusive1']"/>
  112. </xsl:when>
  113. <xsl:otherwise>
  114. <xsl:text>false</xsl:text>
  115. </xsl:otherwise>
  116. </xsl:choose>
  117. </measure_value_inclusive1>
  118. </xsl:if>
  119. <!-- case insensitive flag -->
  120. <case_insensitive>
  121. <xsl:choose>
  122. <xsl:when test="/root/env/param[@name='m_sub_case_insensitive']">
  123. <xsl:value-of select="/root/env/param[@name='m_sub_case_insensitive']"/>
  124. </xsl:when>
  125. <xsl:otherwise>
  126. <xsl:text>false</xsl:text>
  127. </xsl:otherwise>
  128. </xsl:choose>
  129. </case_insensitive>
  130. </xsl:otherwise>
  131. </xsl:choose>
  132. <xsl:apply-templates mode="copy" select="selection/selections"/>
  133. </selection>
  134. </xsl:template>
  135. <!-- -->
  136. <xsl:template match="*" mode="copy">
  137. <xsl:param name="name"/>
  138. <xsl:copy>
  139. <!-- copy all the attributes across -->
  140. <xsl:copy-of select="@*"/>
  141. <!-- decide if we need to add the selectAll element or not attribute -->
  142. <xsl:choose>
  143. <xsl:when test="/root/env/param[@name=concat('m_subData_defaultValue_', $name)] and /root/env/param[@name=concat('m_sub_', $name)]='true' ">
  144. <xsl:element name="selectAll">false</xsl:element>
  145. </xsl:when>
  146. <xsl:when test="/root/env/param[@name=concat('m_subData_defaultValue_', $name)] and not(/root/env/param[@name=concat('m_sub_', $name)]) ">
  147. <xsl:element name="selectAll">true</xsl:element>
  148. </xsl:when>
  149. </xsl:choose>
  150. <!-- copy all the child nodes -->
  151. <xsl:for-each select="node()[not(local-name()='selectAll')]">
  152. <xsl:variable name="nodePosition">
  153. <xsl:value-of select="number(count(preceding-sibling::*)+1)"/>
  154. </xsl:variable>
  155. <xsl:apply-templates mode="copy" select=".">
  156. <xsl:with-param name="name">
  157. <xsl:value-of select="concat(string(local-name()), string($nodePosition))"/>
  158. </xsl:with-param>
  159. </xsl:apply-templates>
  160. </xsl:for-each>
  161. </xsl:copy>
  162. </xsl:template>
  163. <!-- -->
  164. <xsl:template match="text()" mode="copy">
  165. <xsl:param name="name"/>
  166. <xsl:value-of select="."/>
  167. </xsl:template>
  168. </xsl:stylesheet>