xform_13to14.xsl 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 13-->
  10. <!--XSL Transformation from a schema v13 model to a valid BMT schema v14 model-->
  11. <xsl:stylesheet xmlns="http://www.developer.cognos.com/schemas/bmt/14/0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xalan="http://xml.apache.org/xslt" extension-element-prefixes="xalan">
  12. <xsl:output encoding="utf-8" method="xml" indent="yes"/>
  13. <xsl:key name="DS_KEY" match="*[local-name()='source']" use="concat(*[local-name()='database'], ':', *[local-name()='catalog'], ':', *[local-name()='schema'])"/>
  14. <!--root match-->
  15. <xsl:template match="/">
  16. <!--make sure that this transformation is performed on a schema v13 model-->
  17. <xsl:if test="not(contains(/*[local-name() = 'project']/@xsi:schemaLocation, 'http://www.developer.cognos.com/schemas/bmt/13')) ">
  18. <xsl:message terminate="yes">The input file for this transformer must be a schema v13 model.</xsl:message>
  19. </xsl:if>
  20. <xsl:apply-templates/>
  21. </xsl:template>
  22. <!-- general copy -->
  23. <xsl:template match="*">
  24. <xsl:element name="{name(.)}">
  25. <xsl:for-each select="@*">
  26. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  27. </xsl:for-each>
  28. <xsl:apply-templates/>
  29. </xsl:element>
  30. </xsl:template>
  31. <!--change the schema to v14 version-->
  32. <xsl:template match="*[local-name()='project'] ">
  33. <xsl:element name="project" namespace="http://www.developer.cognos.com/schemas/bmt/14/0">
  34. <xsl:for-each select="@*">
  35. <xsl:choose>
  36. <!--change schema from v13 to v14-->
  37. <xsl:when test="name(.) = 'xsi:schemaLocation'">
  38. <xsl:attribute name="{name(.)}"><xsl:value-of select="'http://www.developer.cognos.com/schemas/bmt/14/0 BMTModelSpecification.xsd'"/></xsl:attribute>
  39. </xsl:when>
  40. <xsl:otherwise>
  41. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  42. </xsl:otherwise>
  43. </xsl:choose>
  44. </xsl:for-each>
  45. <xsl:apply-templates/>
  46. </xsl:element>
  47. </xsl:template>
  48. <!--Create a new mandatory empty dataSources object-->
  49. <xsl:template match="*[local-name()='logicalModel']">
  50. <xsl:element name="{name(.)}">
  51. <xsl:for-each select="@*">
  52. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  53. </xsl:for-each>
  54. <xsl:apply-templates/>
  55. </xsl:element>
  56. <xsl:element name="dataSources"/>
  57. </xsl:template>
  58. <!--Create a new "promptInfo" property and move all prompt properties under this new property.
  59. For "promptCascadeOn", "promptDisplayItems", "promptFilterItem", remove if it contains nothing ... if it contains at least one "refobj" entry, then
  60. rename to reftype and set its value to being value of the first "refobj" found-->
  61. <xsl:template match="*[local-name()='queryItem'] ">
  62. <xsl:variable name="cascadeOnFlag" select="count(*[name()='promptCascadeOn'])"/>
  63. <xsl:variable name="displayItemsFlag" select="count(*[name()='promptDisplayItems'])"/>
  64. <xsl:variable name="filterItemsFlag" select="count(*[name()='promptFilterItems'])"/>
  65. <xsl:variable name="promptType" select="*[name()='promptType']"/>
  66. <xsl:element name="queryItem">
  67. <xsl:for-each select="*">
  68. <xsl:choose>
  69. <xsl:when test="name()='displayType'">
  70. <xsl:element name="{name(.)}">
  71. <xsl:value-of select="."/>
  72. </xsl:element>
  73. <xsl:if test="($cascadeOnFlag &gt; 0) or ($displayItemsFlag &gt; 0) or ($filterItemsFlag &gt; 0)">
  74. <xsl:element name="promptInfo">
  75. <xsl:element name="promptType">
  76. <xsl:value-of select="$promptType"/>
  77. </xsl:element>
  78. <xsl:for-each select="../*[local-name()='promptCascadeOn']">
  79. <xsl:variable name="refcount" select="count(./*[local-name()='refobj'])"/>
  80. <xsl:if test="($refcount &gt; 0)">
  81. <xsl:element name="promptCascadeOnRef">
  82. <xsl:value-of select="../*[local-name()='promptCascadeOn']/*[local-name()='refobj']"/>
  83. </xsl:element>
  84. </xsl:if>
  85. </xsl:for-each>
  86. <xsl:for-each select="../*[local-name()='promptDisplayItems']">
  87. <xsl:variable name="refcount" select="count(./*[local-name()='refobj'])"/>
  88. <xsl:if test="($refcount &gt; 0)">
  89. <xsl:element name="promptDisplayItemRef">
  90. <xsl:value-of select="../*[local-name()='promptCascadeOn']/*[local-name()='refobj']"/>
  91. </xsl:element>
  92. </xsl:if>
  93. </xsl:for-each>
  94. <xsl:for-each select="../*[local-name()='promptFilterItems']">
  95. <xsl:variable name="refcount" select="count(./*[local-name()='refobj'])"/>
  96. <xsl:if test="($refcount &gt; 0)">
  97. <xsl:element name="promptFilterItemRef">
  98. <xsl:value-of select="../*[local-name()='promptFilterItems']/*[local-name()='refobj']"/>
  99. </xsl:element>
  100. </xsl:if>
  101. </xsl:for-each>
  102. </xsl:element>
  103. </xsl:if>
  104. </xsl:when>
  105. <xsl:when test="name()='promptType'"/>
  106. <xsl:when test="name()='promptCascadeOn'"/>
  107. <xsl:when test="name()='promptDisplayItems'"/>
  108. <xsl:when test="name()='promptFilterItems'"/>
  109. <!--Copy over the elements and its attributes-->
  110. <xsl:otherwise>
  111. <xsl:element name="{name(.)}">
  112. <xsl:for-each select="@*">
  113. <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
  114. </xsl:for-each>
  115. <xsl:apply-templates/>
  116. </xsl:element>
  117. </xsl:otherwise>
  118. </xsl:choose>
  119. </xsl:for-each>
  120. </xsl:element>
  121. </xsl:template>
  122. </xsl:stylesheet>