xform_10to11.xsl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 10-->
  10. <!--XSL Transformation from a schema v10 model to a valid BMT schema v11 model-->
  11. <xsl:stylesheet xmlns="http://www.developer.cognos.com/schemas/bmt/11/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 v10 model-->
  16. <xsl:if test="not(contains(/*[local-name() = 'project']/@xsi:schemaLocation, 'http://www.developer.cognos.com/schemas/bmt/10')) ">
  17. <xsl:message terminate="yes">The input file for this transformer must be a schema v10 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 v11 version-->
  31. <xsl:template match="*[local-name()='project'] ">
  32. <xsl:element name="project" namespace="http://www.developer.cognos.com/schemas/bmt/11/0">
  33. <xsl:for-each select="@*">
  34. <xsl:choose>
  35. <!--change schema from v10 to v11-->
  36. <xsl:when test="name(.) = 'xsi:schemaLocation'">
  37. <xsl:attribute name="{name(.)}"><xsl:value-of select="'http://www.developer.cognos.com/schemas/bmt/11/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. <xsl:variable name="UPPERCASE" select=" 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' "/>
  48. <xsl:variable name="LOWCASE" select=" 'abcdefghijklmnopqrstuvwxyz' "/>
  49. <!--correct enumerations in queryItem -->
  50. <xsl:template match="*[local-name() = 'queryItem' ]">
  51. <queryItem>
  52. <xsl:for-each select="*">
  53. <xsl:choose>
  54. <xsl:when test="local-name() = 'usage' ">
  55. <usage>
  56. <xsl:variable name="str" select="substring-after(., 'kUsage')"/>
  57. <xsl:value-of select="concat(translate(substring($str, 1, 1), $UPPERCASE, $LOWCASE), substring($str, 2))"/>
  58. </usage>
  59. </xsl:when>
  60. <xsl:when test="local-name() = 'semiAggregate' or local-name() = 'regularAggregate'">
  61. <xsl:element name="{local-name()}">
  62. <xsl:variable name="str" select="substring-after(., 'kAggregateRule')"/>
  63. <xsl:value-of select="concat(translate(substring($str, 1, 1), $UPPERCASE, $LOWCASE), substring($str, 2))"/>
  64. </xsl:element>
  65. </xsl:when>
  66. <xsl:when test="local-name() = 'datatype' ">
  67. <datatype>
  68. <xsl:variable name="str" select="substring-after(., 'kDataType')"/>
  69. <xsl:value-of select="concat(translate(substring($str, 1, 1), $UPPERCASE, $LOWCASE), substring($str, 2))"/>
  70. </datatype>
  71. </xsl:when>
  72. <xsl:when test="local-name() = 'displayType' ">
  73. <displayType>
  74. <xsl:value-of select="concat(translate(substring(., 1, 1), $UPPERCASE, $LOWCASE), substring(., 2))"/>
  75. </displayType>
  76. </xsl:when>
  77. <xsl:otherwise>
  78. <xsl:apply-templates select="."/>
  79. </xsl:otherwise>
  80. </xsl:choose>
  81. </xsl:for-each>
  82. </queryItem>
  83. </xsl:template>
  84. <!--correct enumerations in sql/@type and property/@type -->
  85. <xsl:template match="*[local-name() = 'sql' or local-name()='property' ]">
  86. <xsl:element name="{local-name()}">
  87. <xsl:for-each select="@*">
  88. <xsl:choose>
  89. <xsl:when test="local-name()='type' ">
  90. <xsl:attribute name="type"><xsl:value-of select="concat(translate(substring(., 1, 1), $UPPERCASE, $LOWCASE), substring(., 2))"/></xsl:attribute>
  91. </xsl:when>
  92. <xsl:otherwise>
  93. <xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>
  94. </xsl:otherwise>
  95. </xsl:choose>
  96. </xsl:for-each>
  97. <xsl:apply-templates/>
  98. </xsl:element>
  99. </xsl:template>
  100. <!--correct enumerations in mincard and maxcard -->
  101. <xsl:template match="*[local-name() = 'mincard' or local-name()='maxcard']">
  102. <xsl:element name="{local-name()}">
  103. <xsl:variable name="str" select="substring-after(., 'kCardinality')"/>
  104. <xsl:value-of select="concat(translate(substring($str, 1, 1), $UPPERCASE, $LOWCASE), substring($str, 2))"/>
  105. </xsl:element>
  106. </xsl:template>
  107. </xsl:stylesheet>