xform_21to22.xsl 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?xml version="1.0"?>
  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. <!--XSLT version 21-->
  10. <!--XSL Transformation from a schema v21 model to a valid BMT schema v22 model-->
  11. <xsl:stylesheet xmlns="http://www.developer.cognos.com/schemas/bmt/22/0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  12. <xsl:output encoding="utf-8" method="xml" indent="yes"/>
  13. <!--root match-->
  14. <xsl:template match="/">
  15. <!--make sure that this transformation is performed on a schema v21 model-->
  16. <xsl:if test="not(contains(/*[local-name() = 'project']/@xsi:schemaLocation, 'http://www.developer.cognos.com/schemas/bmt/21')) ">
  17. <xsl:message terminate="yes">The input file for this transformer must be a schema v21 model.</xsl:message>
  18. </xsl:if>
  19. <xsl:apply-templates/>
  20. </xsl:template>
  21. <!-- general copy -->
  22. <xsl:template match="*">
  23. <xsl:element name="{name(.)}">
  24. <xsl:for-each select="@*">
  25. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  26. </xsl:for-each>
  27. <xsl:apply-templates/>
  28. </xsl:element>
  29. </xsl:template>
  30. <!--change the schema to v22 version-->
  31. <xsl:template match="*[local-name()='project'] ">
  32. <xsl:element name="project" namespace="http://www.developer.cognos.com/schemas/bmt/22/0">
  33. <xsl:for-each select="@*">
  34. <xsl:choose>
  35. <!--change schema from v21 to v22-->
  36. <xsl:when test="name(.) = 'xsi:schemaLocation'">
  37. <xsl:attribute name="{name(.)}"><xsl:value-of select="'http://www.developer.cognos.com/schemas/bmt/22/0 BMTModelSpecification.xsd'"/></xsl:attribute>
  38. </xsl:when>
  39. <xsl:otherwise>
  40. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  41. </xsl:otherwise>
  42. </xsl:choose>
  43. </xsl:for-each>
  44. <xsl:apply-templates/>
  45. </xsl:element>
  46. </xsl:template>
  47. <!-- Remove source, correct/add dataSourceRef for dbQuery -->
  48. <xsl:template match="*[local-name()='dbQuery' ]">
  49. <dbQuery>
  50. <sources>
  51. <xsl:choose>
  52. <xsl:when test="*[local-name() = 'dataSourceRef']">
  53. <xsl:apply-templates select="*[local-name() = 'dataSourceRef' ]"/>
  54. </xsl:when>
  55. <xsl:otherwise>
  56. <xsl:variable name="dsPrefix" select=" '[].[dataSources].' "/>
  57. <xsl:variable name="fromTable" select="*[local-name() = 'sql']/*[local-name() = 'table' and contains(., '].') ] "/>
  58. <xsl:choose>
  59. <xsl:when test="$fromTable">
  60. <xsl:for-each select="$fromTable">
  61. <dataSourceRef>
  62. <xsl:value-of select="concat( $dsPrefix, substring-before(., '].'), ']' )"/>
  63. </dataSourceRef>
  64. </xsl:for-each>
  65. </xsl:when>
  66. <xsl:otherwise>
  67. <xsl:variable name="fromSource">
  68. <xsl:for-each select="*[local-name() = 'sources']/*[local-name() = 'source']">
  69. <xsl:variable name="srcKey" select="concat('[', *[local-name() = 'database'], '.', *[local-name() = 'catalog'], '.', *[local-name() = 'schema' ],'.', *[local-name() = 'databaseType'], ']')"/>
  70. <xsl:for-each select="/*/*[local-name() = 'dataSources']/*[local-name() = 'dataSource']">
  71. <xsl:variable name="dsKey" select="concat('[', *[local-name() = 'cmDataSource'],'.', *[local-name() = 'catalog'],'.', *[local-name() = 'schema'], '.', *[local-name() = 'type'], ']')"/>
  72. <xsl:if test="$srcKey = $dsKey">
  73. <dataSourceRef>
  74. <xsl:value-of select="concat($dsPrefix, '[', *[local-name()= 'name'], ']')"/>
  75. </dataSourceRef>
  76. </xsl:if>
  77. </xsl:for-each>
  78. </xsl:for-each>
  79. </xsl:variable>
  80. <xsl:choose>
  81. <xsl:when test="string($fromSource)">
  82. <xsl:copy-of select="$fromSource"/>
  83. </xsl:when>
  84. <xsl:otherwise>
  85. <dataSourceRef>
  86. <xsl:variable name="fromFirstOne" select="/*/*[local-name() = 'dataSources']/*[local-name() = 'dataSource'][1]/*[local-name() = 'name']"/>
  87. <xsl:choose>
  88. <xsl:when test="string($fromFirstOne)">
  89. <xsl:value-of select="concat($dsPrefix, '[', $fromFirstOne, ']') "/>
  90. </xsl:when>
  91. <xsl:otherwise>Empty data source collection was found, it is an Error!!</xsl:otherwise>
  92. </xsl:choose>
  93. </dataSourceRef>
  94. </xsl:otherwise>
  95. </xsl:choose>
  96. </xsl:otherwise>
  97. </xsl:choose>
  98. </xsl:otherwise>
  99. </xsl:choose>
  100. </sources>
  101. <xsl:apply-templates select="*[local-name() != 'sources' and local-name() != 'dataSourceRef']"/>
  102. </dbQuery>
  103. </xsl:template>
  104. <!-- remove source and populate canonicalName from source/name for storedProcedure -->
  105. <xsl:template match="*[local-name() = 'storedProcedure'] ">
  106. <storedProcedure>
  107. <xsl:apply-templates select="*[local-name() = 'dataSourceRef']"/>
  108. <canonicalName>
  109. <xsl:choose>
  110. <xsl:when test="string(*[local-name() = 'canonicalName'])">
  111. <xsl:value-of select="*[local-name() = 'canonicalName']"/>
  112. </xsl:when>
  113. <xsl:otherwise>
  114. <xsl:value-of select="*[local-name() = 'source' ]/*[local-name() = 'name' ]"/>
  115. </xsl:otherwise>
  116. </xsl:choose>
  117. </canonicalName>
  118. <xsl:apply-templates select="*[local-name() != 'dataSourceRef' and local-name() != 'canonicalName' ]"/>
  119. </storedProcedure>
  120. </xsl:template>
  121. <!-- Remove sources from modelQuerySubject -->
  122. <xsl:template match="*[local-name() = 'sources']"/>
  123. <!-- Remove source -->
  124. <xsl:template match="*[local-name() = 'source']"/>
  125. </xsl:stylesheet>