xform_3to4.xsl 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 3-->
  10. <!--XSL Transformation from a schema v3 model to a valid BMT schema v4 model-->
  11. <xsl:stylesheet xmlns="http://www.developer.cognos.com/schemas/bmt/4/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 not performed on a schema v4 model-->
  16. <xsl:if test="/*[local-name() = 'project']/@xsi:schemaLocation = 'http://www.developer.cognos.com/schemas/bmt/4/0 BMTModelSpecification.xsd'">
  17. <xsl:message terminate="yes">The input file for this transformer must be a schema v3 model. You tried to use a schema v4 model.</xsl:message>
  18. </xsl:if>
  19. <xsl:apply-templates/>
  20. </xsl:template>
  21. <!--generic match, copies over the element unless it is redefined later in the file-->
  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 v4 version-->
  31. <xsl:template match="*[local-name() = 'project']">
  32. <xsl:element name="project" namespace="http://www.developer.cognos.com/schemas/bmt/4/0">
  33. <xsl:for-each select="@*">
  34. <xsl:choose>
  35. <!--change schema from v3 to v4-->
  36. <xsl:when test="name(.) = 'xsi:schemaLocation'">
  37. <xsl:attribute name="{name(.)}"><xsl:value-of select="'http://www.developer.cognos.com/schemas/bmt/4/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. <!--rename an includeObj and its enum types-->
  48. <xsl:template match="*[local-name() = 'includeObj']">
  49. <xsl:element name="includeObjectRef">
  50. <xsl:choose>
  51. <xsl:when test=". = 'self'">
  52. <xsl:value-of select="'include'"/>
  53. </xsl:when>
  54. <xsl:when test=". = 'children'">
  55. <xsl:value-of select="'include'"/>
  56. </xsl:when>
  57. <xsl:when test=". = 'excludeChildren'">
  58. <xsl:value-of select="'exclude'"/>
  59. </xsl:when>
  60. <xsl:when test=". = 'excludeSelf'">
  61. <xsl:value-of select="'suppress'"/>
  62. </xsl:when>
  63. </xsl:choose>
  64. </xsl:element>
  65. </xsl:template>
  66. <!--remove name from a storedProcedure, add locale atrribute to name (but not for source/name)-->
  67. <xsl:template match="*[local-name() = 'name']">
  68. <xsl:if test="not(name(parent::*) = 'storedProcedure')">
  69. <xsl:element name="name">
  70. <xsl:if test="not(name(parent::*) = 'source')">
  71. <xsl:choose>
  72. <xsl:when test="not(@locale)">
  73. <xsl:attribute name="locale"><xsl:value-of select="/*[local-name() = 'project']/*[local-name() = 'defaultLocale']"/></xsl:attribute>
  74. </xsl:when>
  75. <xsl:otherwise>
  76. <xsl:attribute name="locale"><xsl:value-of select="@locale"/></xsl:attribute>
  77. </xsl:otherwise>
  78. </xsl:choose>
  79. </xsl:if>
  80. <xsl:apply-templates/>
  81. </xsl:element>
  82. </xsl:if>
  83. </xsl:template>
  84. <!--remove description from a storedProcedure, add locale atrribute to description-->
  85. <xsl:template match="*[local-name() = 'description']">
  86. <xsl:if test="not(name(parent::*) = 'storedProcedure')">
  87. <xsl:element name="description">
  88. <xsl:choose>
  89. <xsl:when test="not(@locale)">
  90. <xsl:attribute name="locale"><xsl:value-of select="/*[local-name() = 'project']/*[local-name() = 'defaultLocale']"/></xsl:attribute>
  91. </xsl:when>
  92. <xsl:otherwise>
  93. <xsl:attribute name="locale"><xsl:value-of select="@locale"/></xsl:attribute>
  94. </xsl:otherwise>
  95. </xsl:choose>
  96. <xsl:apply-templates/>
  97. </xsl:element>
  98. </xsl:if>
  99. </xsl:template>
  100. <!--remove format from a storedProcedure, add locale atrribute to format-->
  101. <xsl:template match="*[local-name() = 'format']">
  102. <xsl:element name="format">
  103. <xsl:choose>
  104. <xsl:when test="not(@locale)">
  105. <xsl:attribute name="locale"><xsl:value-of select="/*[local-name() = 'project']/*[local-name() = 'defaultLocale']"/></xsl:attribute>
  106. </xsl:when>
  107. <xsl:otherwise>
  108. <xsl:attribute name="locale"><xsl:value-of select="@locale"/></xsl:attribute>
  109. </xsl:otherwise>
  110. </xsl:choose>
  111. <xsl:apply-templates/>
  112. </xsl:element>
  113. </xsl:template>
  114. <!--remove lastChanged from a storedProcedure-->
  115. <xsl:template match="*[local-name() = 'lastChanged']">
  116. <xsl:if test="not(name(parent::*) = 'storedProcedure')">
  117. <xsl:element name="lastChanged">
  118. <xsl:apply-templates/>
  119. </xsl:element>
  120. </xsl:if>
  121. </xsl:template>
  122. <!--remove packages and subtree completely-->
  123. <xsl:template match="*[local-name() = 'packages']"/>
  124. </xsl:stylesheet>