xform_20to21.xsl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 20-->
  10. <!--XSL Transformation from a schema v20 model to a valid BMT schema v21 model-->
  11. <xsl:stylesheet xmlns="http://www.developer.cognos.com/schemas/bmt/21/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 v20 model-->
  16. <xsl:if test="not(contains(/*[local-name() = 'project']/@xsi:schemaLocation, 'http://www.developer.cognos.com/schemas/bmt/20')) ">
  17. <xsl:message terminate="yes">The input file for this transformer must be a schema v20 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 v21 version-->
  31. <xsl:template match="*[local-name()='project'] ">
  32. <xsl:element name="project" namespace="http://www.developer.cognos.com/schemas/bmt/21/0">
  33. <xsl:for-each select="@*">
  34. <xsl:choose>
  35. <!--change schema from v20 to v21-->
  36. <xsl:when test="name(.) = 'xsi:schemaLocation'">
  37. <xsl:attribute name="{name(.)}"><xsl:value-of select="'http://www.developer.cognos.com/schemas/bmt/21/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. <!-- Change customer property -->
  48. <xsl:template match="*[local-name() = 'property']">
  49. <property name="{@name}">
  50. <xsl:if test="@type">
  51. <xsl:attribute name="type"><xsl:value-of select="@type"/></xsl:attribute>
  52. </xsl:if>
  53. <xsl:choose>
  54. <xsl:when test="string(@value)">
  55. <xsl:value-of select="@value"/>
  56. </xsl:when>
  57. <xsl:otherwise>
  58. <xsl:value-of select="."/>
  59. </xsl:otherwise>
  60. </xsl:choose>
  61. </property>
  62. </xsl:template>
  63. <!--Add double quote to table names with whitespace -->
  64. <xsl:template match="*[local-name() = 'table']">
  65. <table>
  66. <xsl:variable name="tblName">
  67. <xsl:choose>
  68. <xsl:when test="contains(., '].') ">
  69. <xsl:value-of select="substring-after(., '].')"/>
  70. </xsl:when>
  71. <xsl:otherwise>
  72. <xsl:value-of select="."/>
  73. </xsl:otherwise>
  74. </xsl:choose>
  75. </xsl:variable>
  76. <xsl:variable name="quotedName">
  77. <xsl:choose>
  78. <xsl:when test="contains($tblName, '&#x20;')">
  79. <xsl:value-of select="concat('&#x22;', $tblName,'&#x22;' )"/>
  80. </xsl:when>
  81. <xsl:otherwise>
  82. <xsl:value-of select="$tblName"/>
  83. </xsl:otherwise>
  84. </xsl:choose>
  85. </xsl:variable>
  86. <xsl:choose>
  87. <xsl:when test="contains(., '].')">
  88. <xsl:value-of select="concat(substring-before(., '].' ), '].', $quotedName)"/>
  89. </xsl:when>
  90. <xsl:otherwise>
  91. <xsl:value-of select="$quotedName"/>
  92. </xsl:otherwise>
  93. </xsl:choose>
  94. </table>
  95. </xsl:template>
  96. </xsl:stylesheet>