xform_5to6.xsl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 5-->
  10. <!--XSL Transformation from a schema v5 model to a valid BMT schema v6 model-->
  11. <xsl:stylesheet xmlns="http://www.developer.cognos.com/schemas/bmt/6/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 v5 model-->
  16. <xsl:if test="/*[local-name() = 'project']/@xsi:schemaLocation = 'http://www.developer.cognos.com/schemas/bmt/6/0 BMTModelSpecification.xsd'">
  17. <xsl:message terminate="yes">The input file for this transformer must be a schema v5 model. You tried to use a schema v6 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 v6 version-->
  31. <xsl:template match="*[local-name()='project'] ">
  32. <xsl:element name="project" namespace="http://www.developer.cognos.com/schemas/bmt/6/0">
  33. <xsl:for-each select="@*">
  34. <xsl:choose>
  35. <!--change schema from v5 to v6-->
  36. <xsl:when test="name(.) = 'xsi:schemaLocation'">
  37. <xsl:attribute name="{name(.)}"><xsl:value-of select="'http://www.developer.cognos.com/schemas/bmt/6/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 standard object properties from dbQuery/key and add a non-localizable name-->
  48. <xsl:template match="*[local-name()='dbQuery']">
  49. <xsl:element name="dbQuery">
  50. <xsl:for-each select="@*">
  51. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  52. </xsl:for-each>
  53. <xsl:for-each select="*">
  54. <xsl:choose>
  55. <xsl:when test=" local-name()='key' ">
  56. <xsl:element name="key">
  57. <xsl:element name="name">
  58. <xsl:value-of select="*[local-name()='name']"/>
  59. </xsl:element>
  60. <xsl:apply-templates select="*[local-name()='queryItems_collection']"/>
  61. </xsl:element>
  62. </xsl:when>
  63. <xsl:when test=" local-name()='index' ">
  64. <xsl:element name="index">
  65. <xsl:apply-templates select="*[local-name()='unique' or local-name()='type' or local-name()='queryItems_collection']"/>
  66. </xsl:element>
  67. </xsl:when>
  68. <xsl:otherwise>
  69. <xsl:apply-templates select="."/>
  70. </xsl:otherwise>
  71. </xsl:choose>
  72. </xsl:for-each>
  73. </xsl:element>
  74. </xsl:template>
  75. </xsl:stylesheet>