FMMD_ModelUpdate.xsl 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: FMMD_ModelUpdate
  5. (C) Copyright IBM Corp. 2019, 2020
  6. US Government Users Restricted Rights - Use, duplication or disclosure
  7. restricted by GSA ADP Schedule Contract with IBM Corp.
  8. -->
  9. <xsl:stylesheet version="2.0" xmlns:fm="http://www.developer.cognos.com/schemas/bmt/60/7" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  10. <xsl:output omit-xml-declaration="no" indent="no"/>
  11. <xsl:strip-space elements="*"/>
  12. <xsl:variable name="LOWER_CASE" select="'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþšÿž'"/>
  13. <xsl:variable name="UPPER_CASE" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŠŸŽ'"/>
  14. <!--
  15. ***********************************************************************
  16. This xslt file is used to change case of a model.xml file
  17. User can specify from upper-case to lower-case, or vice vesa.
  18. User can specify one or more specific data soures are used in the search.
  19. User can specify whether dbQuery, or storedProdecure, or both are used in the search.
  20. -->
  21. <!--
  22. SHIFT CASE
  23. Modify the followings to customize your case shift
  24. By default, upper-case is changed to lower-case.
  25. -->
  26. <xsl:variable name="FROM_CASE" select="$UPPER_CASE"/>
  27. <xsl:variable name="TO_CASE" select="$LOWER_CASE"/>
  28. <!--
  29. LIST OF DATA SOURCE NAMES
  30. Modify the followings to match the user's data source names
  31. Otherwise data sources are ignored in search
  32. -->
  33. <xsl:param name="LIST_DS" select="'[LIST OF DATASOURCE NAME]'"/>
  34. <!--
  35. IGNORE DATA SOURCE NAMES
  36. -->
  37. <xsl:param name="IGNORE_DS" select="true()"/>
  38. <!--
  39. QUERY OBJECTS: dbQuery or storedProcedure, or both
  40. By default both dbQuery, and storedProcedure objects are affected
  41. Change xpath on the line 136 of this file to something else to exclude it. eg.
  42. <xsl:variable name="dbQuery" select="fm:definition/fm:dbQuery/fm:sqlxxx"/>
  43. <xsl:variable name="storedProc" select="fm:definition/fm:storedProcedure/fm:dataSourceRefxxx"/>
  44. -->
  45. <xsl:template match="@*|node()">
  46. <xsl:copy>
  47. <xsl:apply-templates select="@*|node()"/>
  48. </xsl:copy>
  49. </xsl:template>
  50. <!-- case shift for canonicalName of storedProcedure -->
  51. <xsl:template match="//fm:querySubject/fm:definition/fm:storedProcedure/fm:canonicalName">
  52. <xsl:copy>
  53. <xsl:apply-templates select="@*"/>
  54. <xsl:value-of select="translate(., $FROM_CASE, $TO_CASE)"/>
  55. </xsl:copy>
  56. </xsl:template>
  57. <xsl:template match="//fm:querySubject/fm:definition/fm:storedProcedure/*[not(name()='canonicalName')]">
  58. <xsl:copy-of select="."/>
  59. </xsl:template>
  60. <xsl:template match="//fm:querySubject/fm:definition/fm:storedProcedure">
  61. <xsl:copy>
  62. <xsl:apply-templates select="@*"/>
  63. <xsl:for-each select=".">
  64. <xsl:apply-templates/>
  65. </xsl:for-each>
  66. </xsl:copy>
  67. </xsl:template>
  68. <!-- case shift for sql of dbQuery -->
  69. <xsl:template match="//fm:querySubject/fm:definition/fm:dbQuery/fm:sql">
  70. <xsl:copy>
  71. <xsl:apply-templates select="@*"/>
  72. <xsl:value-of select="concat(substring-before(.,']'), ']', translate(substring-after(.,']'), $FROM_CASE, $TO_CASE))"/>
  73. </xsl:copy>
  74. </xsl:template>
  75. <xsl:template match="//fm:querySubject/fm:definition/fm:dbQuery/*[not(name()='sql')]">
  76. <xsl:copy-of select="."/>
  77. </xsl:template>
  78. <xsl:template match="//fm:querySubject/fm:definition/fm:dbQuery">
  79. <xsl:copy>
  80. <xsl:apply-templates select="@*"/>
  81. <xsl:for-each select=".">
  82. <xsl:apply-templates/>
  83. </xsl:for-each>
  84. </xsl:copy>
  85. </xsl:template>
  86. <xsl:template match="//fm:querySubject/fm:definition/*[not(name()='dbQuery' or name()='storedProcedure')]">
  87. <xsl:copy-of select="."/>
  88. </xsl:template>
  89. <xsl:template match="//fm:querySubject/fm:definition">
  90. <xsl:copy>
  91. <xsl:apply-templates select="@*"/>
  92. <xsl:for-each select=".">
  93. <xsl:apply-templates/>
  94. </xsl:for-each>
  95. </xsl:copy>
  96. </xsl:template>
  97. <!-- case shift for externalName of queryItems -->
  98. <xsl:template match="//fm:querySubject/fm:queryItem/fm:externalName">
  99. <xsl:copy>
  100. <xsl:apply-templates select="@*"/>
  101. <xsl:value-of select="translate(., $FROM_CASE, $TO_CASE)"/>
  102. </xsl:copy>
  103. </xsl:template>
  104. <xsl:template match="//fm:querySubject/fm:queryItem/*[not(name()='externalName')]">
  105. <xsl:copy-of select="."/>
  106. </xsl:template>
  107. <xsl:template match="//fm:querySubject/fm:queryItem">
  108. <xsl:copy>
  109. <xsl:apply-templates select="@*"/>
  110. <xsl:for-each select=".">
  111. <xsl:apply-templates/>
  112. </xsl:for-each>
  113. </xsl:copy>
  114. </xsl:template>
  115. <!-- deep copy of all children except queryItem and definition-->
  116. <xsl:template match="//fm:querySubject/*[not(name()='queryItem' or name()='definition')]">
  117. <xsl:copy-of select="."/>
  118. </xsl:template>
  119. <!-- DBQUERY or STORED PROCEDURE -->
  120. <xsl:template match="//fm:querySubject">
  121. <xsl:variable name="dbQuery_cognos" select="fm:definition/fm:dbQuery/fm:sql[@type='cognos']"/>
  122. <xsl:variable name="storedProc" select="fm:definition/fm:storedProcedure/fm:dataSourceRef"/>
  123. <xsl:variable name="dbQuery_trivial">
  124. <xsl:choose>
  125. <xsl:when test="starts-with($dbQuery_cognos, 'Select *from[')">
  126. <xsl:value-of select="$dbQuery_cognos"/>
  127. </xsl:when>
  128. <xsl:otherwise>
  129. <xsl:value-of select="''"/>
  130. </xsl:otherwise>
  131. </xsl:choose>
  132. </xsl:variable>
  133. <xsl:variable name="dbQuery_ds" select="concat('[', substring-after(substring-before($dbQuery_trivial, ']'), '['), ']')"/>
  134. <xsl:variable name="storedProc_ds" select="concat('[', substring-before(substring-after($storedProc, '[].[dataSources].['), ']'), ']')"/>
  135. <xsl:variable name="match_with_ds" select="contains($LIST_DS, $dbQuery_ds) or contains($LIST_DS, $storedProc_ds)"/>
  136. <xsl:variable name="match_without_ds" select="$IGNORE_DS and (not(contains($dbQuery_ds, '[]')) or not(contains($storedProc_ds, '[]')))"/>
  137. <xsl:variable name="db_sp_match" select="$match_with_ds or $match_without_ds"/>
  138. <xsl:for-each select=".">
  139. <xsl:choose>
  140. <xsl:when test="$db_sp_match">
  141. <xsl:copy>
  142. <xsl:apply-templates select="@*"/>
  143. <xsl:apply-templates/>
  144. </xsl:copy>
  145. </xsl:when>
  146. <xsl:otherwise>
  147. <xsl:copy-of select="."/>
  148. </xsl:otherwise>
  149. </xsl:choose>
  150. </xsl:for-each>
  151. </xsl:template>
  152. <xsl:template match="//fm:function/fm:canonicalName">
  153. <xsl:copy>
  154. <xsl:apply-templates select="@*"/>
  155. <xsl:value-of select="translate(., $FROM_CASE, $TO_CASE)"/>
  156. </xsl:copy>
  157. </xsl:template>
  158. <xsl:template match="//fm:function/*[not(name()='canonicalName')]">
  159. <xsl:copy-of select="."/>
  160. </xsl:template>
  161. <!-- FUNCTIONS -->
  162. <xsl:template match="//fm:function">
  163. <xsl:variable name="function" select="fm:dataSourceRef"/>
  164. <xsl:variable name="function_ds" select="concat('[', substring-before(substring-after($function, '[].[dataSources].['), ']'), ']')"/>
  165. <xsl:variable name="fn_match" select="contains($LIST_DS, $function_ds) or ($IGNORE_DS and not(contains($function_ds,'[]')))"/>
  166. <xsl:for-each select=".">
  167. <xsl:choose>
  168. <xsl:when test="$fn_match">
  169. <xsl:copy>
  170. <xsl:apply-templates select="@*"/>
  171. <xsl:apply-templates/>
  172. </xsl:copy>
  173. </xsl:when>
  174. <xsl:otherwise>
  175. <xsl:copy-of select="."/>
  176. </xsl:otherwise>
  177. </xsl:choose>
  178. </xsl:for-each>
  179. </xsl:template>
  180. </xsl:stylesheet>