xform_23to24.xsl 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 23-->
  10. <!--XSL Transformation from a schema v23 model to a valid BMT schema v24 model-->
  11. <xsl:stylesheet xmlns="http://www.developer.cognos.com/schemas/bmt/24/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 v23 model-->
  16. <xsl:if test="not(contains(/*[local-name() = 'project']/@xsi:schemaLocation, 'http://www.developer.cognos.com/schemas/bmt/23')) ">
  17. <xsl:message terminate="yes">The input file for this transformer must be a schema v23 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. <xsl:variable name="lowcase" select=" 'abcdefghijklmnopqrstuvwxyz' "/>
  31. <xsl:variable name="UPPERCASE" select=" 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' "/>
  32. <xsl:variable name="DEFAULT_LOCALE" select="translate(/*/*[local-name() = 'defaultLocale'], $lowcase, $UPPERCASE)"/>
  33. <!--change the schema to v24 version-->
  34. <xsl:template match="*[local-name()='project'] ">
  35. <xsl:element name="project" namespace="http://www.developer.cognos.com/schemas/bmt/24/0">
  36. <xsl:for-each select="@*">
  37. <xsl:choose>
  38. <!--change schema from v23 to v24-->
  39. <xsl:when test="name(.) = 'xsi:schemaLocation'">
  40. <xsl:attribute name="{name(.)}"><xsl:value-of select="'http://www.developer.cognos.com/schemas/bmt/24/0 BMTModelSpecification.xsd'"/></xsl:attribute>
  41. </xsl:when>
  42. <xsl:otherwise>
  43. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  44. </xsl:otherwise>
  45. </xsl:choose>
  46. </xsl:for-each>
  47. <xsl:variable name="newName">
  48. <xsl:for-each select="*[local-name() = 'name']">
  49. <xsl:if test=" translate( @locale , $lowcase, $UPPERCASE ) = $DEFAULT_LOCALE ">
  50. <xsl:value-of select="."/>
  51. </xsl:if>
  52. </xsl:for-each>
  53. </xsl:variable>
  54. <name>
  55. <xsl:choose>
  56. <xsl:when test="string($newName)">
  57. <xsl:value-of select="$newName"/>
  58. </xsl:when>
  59. <xsl:otherwise>
  60. <xsl:value-of select="*[local-name()='name'][1]"/>
  61. </xsl:otherwise>
  62. </xsl:choose>
  63. </name>
  64. <xsl:apply-templates select="*[local-name() != 'name' and local-name() != 'description' and local-name() != 'lastChanged' and local-name() != 'screenTip' ]"/>
  65. </xsl:element>
  66. </xsl:template>
  67. <xsl:template match="*[local-name() = 'relationship' or local-name() = 'relationshipShortcut' or local-name() = 'securityView' ]">
  68. <xsl:element name="{local-name()}">
  69. <xsl:for-each select="@*">
  70. <xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>
  71. </xsl:for-each>
  72. <xsl:variable name="newName">
  73. <xsl:for-each select="*[local-name() = 'name']">
  74. <xsl:if test=" translate( @locale , $lowcase, $UPPERCASE ) = $DEFAULT_LOCALE ">
  75. <xsl:value-of select="."/>
  76. </xsl:if>
  77. </xsl:for-each>
  78. </xsl:variable>
  79. <name>
  80. <xsl:choose>
  81. <xsl:when test="string($newName)">
  82. <xsl:value-of select="$newName"/>
  83. </xsl:when>
  84. <xsl:otherwise>
  85. <xsl:value-of select="*[local-name()='name'][1]"/>
  86. </xsl:otherwise>
  87. </xsl:choose>
  88. </name>
  89. <xsl:apply-templates select="*[local-name() != 'name' and local-name() != 'description' and local-name() != 'lastChanged' and local-name() != 'screenTip' ]"/>
  90. </xsl:element>
  91. </xsl:template>
  92. </xsl:stylesheet>