123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?xml version="1.0"?>
- <!--
- Licensed Materials - Property of IBM
- IBM Cognos Products: fmmd
- (C) Copyright IBM Corp. 2003, 2013
- US Government Users Restricted Rights - Use, duplication or disclosure
- restricted by GSA ADP Schedule Contract with IBM Corp.
- -->
- <!--XSLT version 21-->
- <!--XSL Transformation from a schema v21 model to a valid BMT schema v22 model-->
- <xsl:stylesheet xmlns="http://www.developer.cognos.com/schemas/bmt/22/0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <xsl:output encoding="utf-8" method="xml" indent="yes"/>
- <!--root match-->
- <xsl:template match="/">
- <!--make sure that this transformation is performed on a schema v21 model-->
- <xsl:if test="not(contains(/*[local-name() = 'project']/@xsi:schemaLocation, 'http://www.developer.cognos.com/schemas/bmt/21')) ">
- <xsl:message terminate="yes">The input file for this transformer must be a schema v21 model.</xsl:message>
- </xsl:if>
- <xsl:apply-templates/>
- </xsl:template>
- <!-- general copy -->
- <xsl:template match="*">
- <xsl:element name="{name(.)}">
- <xsl:for-each select="@*">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
- </xsl:for-each>
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:template>
- <!--change the schema to v22 version-->
- <xsl:template match="*[local-name()='project'] ">
- <xsl:element name="project" namespace="http://www.developer.cognos.com/schemas/bmt/22/0">
- <xsl:for-each select="@*">
- <xsl:choose>
- <!--change schema from v21 to v22-->
- <xsl:when test="name(.) = 'xsi:schemaLocation'">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="'http://www.developer.cognos.com/schemas/bmt/22/0 BMTModelSpecification.xsd'"/></xsl:attribute>
- </xsl:when>
- <xsl:otherwise>
- <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:template>
- <!-- Remove source, correct/add dataSourceRef for dbQuery -->
- <xsl:template match="*[local-name()='dbQuery' ]">
- <dbQuery>
- <sources>
- <xsl:choose>
- <xsl:when test="*[local-name() = 'dataSourceRef']">
- <xsl:apply-templates select="*[local-name() = 'dataSourceRef' ]"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:variable name="dsPrefix" select=" '[].[dataSources].' "/>
- <xsl:variable name="fromTable" select="*[local-name() = 'sql']/*[local-name() = 'table' and contains(., '].') ] "/>
- <xsl:choose>
- <xsl:when test="$fromTable">
- <xsl:for-each select="$fromTable">
- <dataSourceRef>
- <xsl:value-of select="concat( $dsPrefix, substring-before(., '].'), ']' )"/>
- </dataSourceRef>
- </xsl:for-each>
- </xsl:when>
- <xsl:otherwise>
- <xsl:variable name="fromSource">
- <xsl:for-each select="*[local-name() = 'sources']/*[local-name() = 'source']">
- <xsl:variable name="srcKey" select="concat('[', *[local-name() = 'database'], '.', *[local-name() = 'catalog'], '.', *[local-name() = 'schema' ],'.', *[local-name() = 'databaseType'], ']')"/>
- <xsl:for-each select="/*/*[local-name() = 'dataSources']/*[local-name() = 'dataSource']">
- <xsl:variable name="dsKey" select="concat('[', *[local-name() = 'cmDataSource'],'.', *[local-name() = 'catalog'],'.', *[local-name() = 'schema'], '.', *[local-name() = 'type'], ']')"/>
- <xsl:if test="$srcKey = $dsKey">
- <dataSourceRef>
- <xsl:value-of select="concat($dsPrefix, '[', *[local-name()= 'name'], ']')"/>
- </dataSourceRef>
- </xsl:if>
- </xsl:for-each>
- </xsl:for-each>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="string($fromSource)">
- <xsl:copy-of select="$fromSource"/>
- </xsl:when>
- <xsl:otherwise>
- <dataSourceRef>
- <xsl:variable name="fromFirstOne" select="/*/*[local-name() = 'dataSources']/*[local-name() = 'dataSource'][1]/*[local-name() = 'name']"/>
- <xsl:choose>
- <xsl:when test="string($fromFirstOne)">
- <xsl:value-of select="concat($dsPrefix, '[', $fromFirstOne, ']') "/>
- </xsl:when>
- <xsl:otherwise>Empty data source collection was found, it is an Error!!</xsl:otherwise>
- </xsl:choose>
- </dataSourceRef>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </sources>
- <xsl:apply-templates select="*[local-name() != 'sources' and local-name() != 'dataSourceRef']"/>
- </dbQuery>
- </xsl:template>
- <!-- remove source and populate canonicalName from source/name for storedProcedure -->
- <xsl:template match="*[local-name() = 'storedProcedure'] ">
- <storedProcedure>
- <xsl:apply-templates select="*[local-name() = 'dataSourceRef']"/>
- <canonicalName>
- <xsl:choose>
- <xsl:when test="string(*[local-name() = 'canonicalName'])">
- <xsl:value-of select="*[local-name() = 'canonicalName']"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="*[local-name() = 'source' ]/*[local-name() = 'name' ]"/>
- </xsl:otherwise>
- </xsl:choose>
- </canonicalName>
- <xsl:apply-templates select="*[local-name() != 'dataSourceRef' and local-name() != 'canonicalName' ]"/>
- </storedProcedure>
- </xsl:template>
- <!-- Remove sources from modelQuerySubject -->
- <xsl:template match="*[local-name() = 'sources']"/>
- <!-- Remove source -->
- <xsl:template match="*[local-name() = 'source']"/>
- </xsl:stylesheet>
|