fmmd_generalTemplates.xsl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: fmmd
  5. (C) Copyright IBM Corp. 2003, 2013
  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="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fmfunc="http://www.developer.cognos.com/bmt" exclude-result-prefixes="fmfunc">
  10. <xsl:include href="fmmd_UpgradeStringResources.xsl"/>
  11. <xsl:output encoding="utf-8" method="xml" indent="yes"/>
  12. <!-- Template: Verify the schema # -->
  13. <xsl:template match="/">
  14. <!-- Make sure that this transformation is performed on a model using the old schema -->
  15. <xsl:variable name="inputNamespace" select="/*[local-name() = 'project']/@xsi:schemaLocation"/>
  16. <xsl:if test="not(contains($inputNamespace, concat('http://www.developer.cognos.com/schemas/bmt/', $nOldSchema))) ">
  17. <xsl:message terminate="yes">
  18. <xsl:value-of select="concat('The namespace of the model to be upgraded &quot;', $inputNamespace, '&quot; does not contain the expected schema number (', $nOldSchema, ').')"/>
  19. </xsl:message>
  20. </xsl:if>
  21. <xsl:apply-templates select="node()"/>
  22. </xsl:template>
  23. <!-- Template: General copy. Fix to prevent improper escaping of CDATA (should be copied over as is)-->
  24. <!--
  25. <xsl:template match="value/text()">
  26. <xsl:if test="name(.) = 'cdata'">
  27. <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
  28. <xsl:value-of disable-output-escaping="yes" select="."/>
  29. <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
  30. </xsl:if>
  31. <xsl:if test="not(name(.) = 'cdata')">
  32. <xsl:value-of disable-output-escaping="no" select="."/>
  33. </xsl:if>
  34. </xsl:template>
  35. -->
  36. <!-- Template: General copy for comments and processing instructions -->
  37. <xsl:template name="copyText" match="text() | comment() | processing-instruction()">
  38. <xsl:copy>
  39. <xsl:apply-templates select="@*|*"/>
  40. </xsl:copy>
  41. </xsl:template>
  42. <!-- Template: General copy -->
  43. <xsl:template match="*">
  44. <xsl:element name="{local-name(.)}" namespace="{$sEmptyNamespace}">
  45. <xsl:for-each select="@*">
  46. <xsl:attribute name="{local-name(.)}"><xsl:value-of select="."/></xsl:attribute>
  47. </xsl:for-each>
  48. <xsl:apply-templates select="node()"/>
  49. </xsl:element>
  50. </xsl:template>
  51. <!-- Template: Copy the current context's element tree -->
  52. <xsl:template name="myCopy">
  53. <xsl:param name="elemName">
  54. <xsl:value-of select="local-name(.)"/>
  55. </xsl:param>
  56. <xsl:choose>
  57. <xsl:when test="self::text()">
  58. <xsl:call-template name="copyText"/>
  59. </xsl:when>
  60. <xsl:otherwise>
  61. <xsl:element name="{$elemName}" namespace="{$sEmptyNamespace}">
  62. <xsl:for-each select="@*">
  63. <xsl:attribute name="{local-name(.)}"><xsl:value-of select="."/></xsl:attribute>
  64. </xsl:for-each>
  65. <xsl:apply-templates select="./node()"/>
  66. </xsl:element>
  67. </xsl:otherwise>
  68. </xsl:choose>
  69. </xsl:template>
  70. <!-- Template: Copy the current context's attributes over -->
  71. <xsl:template name="myCopyAttributes">
  72. <xsl:for-each select="@*">
  73. <xsl:attribute name="{local-name(.)}"><xsl:value-of select="."/></xsl:attribute>
  74. </xsl:for-each>
  75. </xsl:template>
  76. <!-- Template: Annotate the given value -->
  77. <xsl:template name="annotate">
  78. <xsl:param name="value"/>
  79. <xsl:comment>
  80. <xsl:value-of select="$value"/>
  81. </xsl:comment>
  82. </xsl:template>
  83. <!-- Template: Helper function to find a single occurence of a delimited string-->
  84. <xsl:template name="substring-findDelimited">
  85. <xsl:param name="strString"/>
  86. <xsl:param name="strLeftDelimiter"/>
  87. <xsl:param name="strRightDelimiter"/>
  88. <xsl:value-of select="substring-before(substring-after($strString, $strLeftDelimiter), $strRightDelimiter)"/>
  89. </xsl:template>
  90. <!-- Template: Helper function to find and replace all occurences of a given delimited string. NOTE: Delimiters are included in the replacement -->
  91. <xsl:template name="substring-replaceDelimited">
  92. <xsl:param name="strString"/>
  93. <xsl:param name="strLeftDelimiter"/>
  94. <xsl:param name="strRightDelimiter"/>
  95. <xsl:param name="strReplace"/>
  96. <xsl:variable name="strMatch">
  97. <xsl:call-template name="substring-findDelimited">
  98. <xsl:with-param name="strString" select="$strRightMatch"/>
  99. <xsl:with-param name="strLeftDelimiter" select="$strLeftDelimiter"/>
  100. <xsl:with-param name="strRightDelimiter" select="$strRightDelimiter"/>
  101. <xsl:with-param name="strReplace" select="$strReplace"/>
  102. </xsl:call-template>
  103. </xsl:variable>
  104. <xsl:variable name="strMatchDelimited" select="concat($strLeftDelimiter, $strMatch, $strRightDelimiter)"/>
  105. <xsl:choose>
  106. <xsl:when test="contains($strString, $strMatchDelimited)">
  107. <xsl:variable name="strLeftMatch" select="substring-before($strString, $strLeftDelimiter)"/>
  108. <xsl:variable name="strRightMatch" select="substring-after(substring-after($strString, $strLeftDelimiter), $strRightDelimiter)"/>
  109. <xsl:value-of select="concat($strLeftMatch, $strReplace)"/>
  110. <xsl:call-template name="substring-replaceDelimited">
  111. <xsl:with-param name="strString" select="$strRightMatch"/>
  112. <xsl:with-param name="strLeftDelimiter" select="$strLeftDelimiter"/>
  113. <xsl:with-param name="strRightDelimiter" select="$strRightDelimiter"/>
  114. <xsl:with-param name="strReplace" select="$strReplace"/>
  115. </xsl:call-template>
  116. </xsl:when>
  117. <xsl:otherwise>
  118. <xsl:value-of select="$strString"/>
  119. </xsl:otherwise>
  120. </xsl:choose>
  121. </xsl:template>
  122. <!-- Template: Helper function to find and replace all occurences of a given string -->
  123. <xsl:template name="substring-replace">
  124. <xsl:param name="strString"/>
  125. <xsl:param name="strFind"/>
  126. <xsl:param name="strReplace"/>
  127. <xsl:choose>
  128. <xsl:when test="contains($strString, $strFind)">
  129. <xsl:value-of select="concat(substring-before($strString, $strFind), $strReplace)"/>
  130. <xsl:call-template name="substring-replace">
  131. <xsl:with-param name="strString" select="substring-after($strString, $strFind)"/>
  132. <xsl:with-param name="strFind" select="$strFind"/>
  133. <xsl:with-param name="strReplace" select="$strReplace"/>
  134. </xsl:call-template>
  135. </xsl:when>
  136. <xsl:otherwise>
  137. <xsl:value-of select="$strString"/>
  138. </xsl:otherwise>
  139. </xsl:choose>
  140. </xsl:template>
  141. <!-- Template: Update the schema version-->
  142. <xsl:template match="/*[local-name()='project'] ">
  143. <xsl:element name="project" namespace="{$sEmptyNamespace}">
  144. <xsl:for-each select="@*">
  145. <xsl:choose>
  146. <!-- Update the schema # -->
  147. <xsl:when test="name(.) = 'xsi:schemaLocation'">
  148. <xsl:attribute name="{name(.)}"><xsl:value-of select="concat($sEmptyNamespace, ' BMTModelSpecification.xsd')"/></xsl:attribute>
  149. </xsl:when>
  150. <xsl:otherwise>
  151. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  152. </xsl:otherwise>
  153. </xsl:choose>
  154. </xsl:for-each>
  155. <xsl:apply-templates select="node()"/>
  156. </xsl:element>
  157. </xsl:template>
  158. <!-- Template: Given a model object, search the model for a relationship
  159. which uses it and return the other side of the relationship.
  160. -->
  161. <xsl:template name="resolveRelationshipReference">
  162. <xsl:param name="refObj"/>
  163. <xsl:variable name="relationship" select="key('relationship_using_leftright_refobj', $refObj)"/>
  164. <xsl:variable name="leftRefobj" select="string($relationship/*[local-name() = 'expression']/*[local-name() = 'refobj'][1])"/>
  165. <xsl:variable name="rightRefobj" select="string($relationship/*[local-name() = 'expression']/*[local-name() = 'refobj'][2])"/>
  166. <xsl:choose>
  167. <xsl:when test="$leftRefobj = $refObj">
  168. <xsl:value-of select="$rightRefobj"/>
  169. </xsl:when>
  170. <xsl:when test="$rightRefobj = $refObj">
  171. <xsl:value-of select="$leftRefobj"/>
  172. </xsl:when>
  173. <xsl:otherwise>
  174. <xsl:value-of select="$refObj"/>
  175. </xsl:otherwise>
  176. </xsl:choose>
  177. </xsl:template>
  178. <!-- Template: Given a refobj to either a dimesion or a measure dimension,
  179. search the model for a scopeRelationship which uses it and return the other
  180. side of the scopeRelationship.
  181. -->
  182. <xsl:template name="resolveScopeRelationshipReference">
  183. <xsl:param name="refObj"/>
  184. <xsl:variable name="scopeRelationship" select="key('scopeRelationship_using_leftright_refobj', $refObj)"/>
  185. <xsl:variable name="leftRefobj" select="string($scopeRelationship/*[local-name() = 'left']/*[local-name() = 'refobj'])"/>
  186. <xsl:variable name="rightRefobj" select="string($scopeRelationship/*[local-name() = 'right']/*[local-name() = 'refobj'])"/>
  187. <xsl:choose>
  188. <xsl:when test="$leftRefobj = $refObj">
  189. <xsl:value-of select="$rightRefobj"/>
  190. </xsl:when>
  191. <xsl:when test="$rightRefobj = $refObj">
  192. <xsl:value-of select="$leftRefobj"/>
  193. </xsl:when>
  194. <xsl:otherwise>
  195. <xsl:value-of select="$refObj"/>
  196. </xsl:otherwise>
  197. </xsl:choose>
  198. </xsl:template>
  199. <!-- Template: Return a localized string value given an ID and a locale. For now accept 4 replacement strings.
  200. -->
  201. <xsl:template name="getLocalizedString">
  202. <xsl:param name="stringID"/>
  203. <xsl:param name="localeVal"/>
  204. <xsl:param name="string1"/>
  205. <xsl:param name="string2"/>
  206. <xsl:param name="string3"/>
  207. <xsl:param name="string4"/>
  208. <xsl:param name="bLocalize" select="true()"/>
  209. <xsl:choose>
  210. <!-- xsl:use-when="function-available('fmfunc:GetLocalizedString')" -->
  211. <xsl:when test="$bLocalize">
  212. <!--
  213. <xsl:message>
  214. <xsl:value-of select="concat('Localized string[', $localeVal, ']: ', fmfunc:GetLocalizedString($stringID, $localeVal))"/>
  215. </xsl:message>
  216. -->
  217. <xsl:value-of select="fmfunc:GetLocalizedString($stringID, $localeVal, $string1, $string2, $string3, $string4)"/>
  218. </xsl:when>
  219. <xsl:otherwise>
  220. <xsl:value-of select="$stringID"/>
  221. </xsl:otherwise>
  222. </xsl:choose>
  223. </xsl:template>
  224. <!-- Template: Set attribute/element values to lowercase
  225. -->
  226. <xsl:template name="lowercaseValues">
  227. <xsl:param name="nodeset" select="."/>
  228. <xsl:for-each select="$nodeset">
  229. <xsl:apply-templates select="." mode="lowercaseValues"/>
  230. </xsl:for-each>
  231. </xsl:template>
  232. <xsl:template match="*" mode="lowercaseValues">
  233. <xsl:element name="{local-name(.)}" namespace="{$sEmptyNamespace}">
  234. <xsl:apply-templates select="@*|node()" mode="lowercaseValues"/>
  235. </xsl:element>
  236. </xsl:template>
  237. <xsl:template match="text()" mode="lowercaseValues">
  238. <xsl:value-of select="translate(., $uppercase, $lowercase)"/>
  239. </xsl:template>
  240. <xsl:template match="@*" mode="lowercaseValues">
  241. <xsl:attribute name="{local-name(.)}"><xsl:value-of select="translate(., $uppercase, $lowercase)"/></xsl:attribute>
  242. </xsl:template>
  243. <!-- Template: Output a trace message for debugging purposes.
  244. -->
  245. <xsl:template name="TRACE">
  246. <xsl:param name="msg"/>
  247. <!-- xsl:use-when="function-available('fmfunc:GetDateTime')" -->
  248. <xsl:if test="$nDebug">
  249. <xsl:message>
  250. <xsl:value-of select="concat(fmfunc:GetDateTime(), ': ', $msg)"/>
  251. </xsl:message>
  252. </xsl:if>
  253. </xsl:template>
  254. <xsl:template name="TRACE_BEGIN">
  255. <xsl:param name="templateID"/>
  256. <xsl:param name="msg"/>
  257. <!-- xsl:use-when="function-available('fmfunc:GetDateTime')" -->
  258. <xsl:if test="$nDebug">
  259. <xsl:message>
  260. <xsl:value-of select="concat(fmfunc:GetDateTime(), ': ', $templateID, ' ', $msg)"/>
  261. </xsl:message>
  262. </xsl:if>
  263. </xsl:template>
  264. <xsl:template name="TRACE_END">
  265. <xsl:param name="templateID"/>
  266. <xsl:param name="timerID"/>
  267. <!-- xsl:use-when="function-available('fmfunc:GetDateTime')" -->
  268. <xsl:variable name="TRACE_STOP" select="fmfunc:TimerStop($timerID)"/>
  269. <xsl:if test="$templateID = $nDebug">
  270. <xsl:message>
  271. <xsl:value-of select="concat(fmfunc:GetDateTime(), ': ', $templateID, ' DONE in [', $TRACE_STOP, '] seconds. ')"/>
  272. </xsl:message>
  273. </xsl:if>
  274. </xsl:template>
  275. <!-- =============================================================================== -->
  276. <!-- Global variables: -->
  277. <!-- =============================================================================== -->
  278. <xsl:variable name="nDebug" select="false()"/>
  279. <xsl:variable name="nDebugTimer" select="0"/>
  280. <xsl:variable name="lowercase" select="string('abcdefghijklmnopqrstuvwxyz')"/>
  281. <xsl:variable name="uppercase" select="string('ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
  282. <xsl:variable name="defaultLocale" select="translate(/*[local-name()='project']/*[local-name()='defaultLocale'], $uppercase, $lowercase)"/>
  283. <xsl:key
  284. name="scopeRelationship_using_leftright_refobj"
  285. match="*[local-name() = 'scopeRelationship']"
  286. use="*[local-name() = 'left' or local-name() = 'right']/*[local-name() = 'refobj']"/>
  287. <xsl:key
  288. name="relationship_using_leftright_refobj"
  289. match="*[local-name() = 'relationship']"
  290. use="*[local-name() = 'left' or local-name() = 'right']/*[local-name() = 'refobj']"/>
  291. </xsl:stylesheet>