xform_26to27.xsl 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 26-->
  10. <!--XSL Transformation from a schema v26 model to a valid BMT schema v27 model-->
  11. <xsl:stylesheet xmlns="http://www.developer.cognos.com/schemas/bmt/27/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 v26 model-->
  16. <xsl:if test="not(contains(/*[local-name() = 'project']/@xsi:schemaLocation, 'http://www.developer.cognos.com/schemas/bmt/26')) ">
  17. <xsl:message terminate="yes">The input file for this transformer must be a schema v26 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 v27 version-->
  31. <xsl:template match="*[local-name()='project'] ">
  32. <xsl:element name="project" namespace="http://www.developer.cognos.com/schemas/bmt/27/0">
  33. <xsl:for-each select="@*">
  34. <xsl:choose>
  35. <!--change schema from v26 to v27-->
  36. <xsl:when test="name(.) = 'xsi:schemaLocation'">
  37. <xsl:attribute name="{name(.)}"><xsl:value-of select="'http://www.developer.cognos.com/schemas/bmt/27/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:template match="*[local-name() = 'mdQuery']">
  48. <mdQuery>
  49. <sources>
  50. <xsl:apply-templates select="*[local-name() = 'dataSourceRef' ]"/>
  51. </sources>
  52. <xsl:apply-templates select="*[local-name() = 'dimension'] "/>
  53. </mdQuery>
  54. </xsl:template>
  55. <xsl:template match="*[local-name() = 'dataSource']">
  56. <xsl:element name="{name(.)}">
  57. <xsl:for-each select="@*">
  58. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  59. </xsl:for-each>
  60. <xsl:apply-templates select="*[local-name() != 'schema' and local-name() != 'type'] "/>
  61. <xsl:variable name="ref" select="concat('[].[dataSources].[', *[local-name()='name'], ']')"/>
  62. <xsl:variable name="cube" select="//*[local-name() = 'mdQuery' and *[local-name()='dataSourceRef' and . = $ref] ]/*[local-name() = 'cube']"/>
  63. <xsl:if test="string($cube)">
  64. <cube>
  65. <xsl:value-of select="$cube"/>
  66. </cube>
  67. </xsl:if>
  68. <xsl:apply-templates select="*[local-name() = 'schema' or local-name() = 'type'] "/>
  69. </xsl:element>
  70. </xsl:template>
  71. </xsl:stylesheet>