123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- <?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 18-->
- <!--XSL Transformation from a schema v18 model to a valid BMT schema v19 model-->
- <xsl:stylesheet xmlns="http://www.developer.cognos.com/schemas/bmt/19/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">
- <xsl:output encoding="utf-8" method="xml" indent="yes"/>
- <xsl:key name="DS_KEY" match="*[local-name()='source']" use="concat(*[local-name()='database'], ':', *[local-name()='catalog'], ':', *[local-name()='schema'])"/>
- <!--root match-->
- <xsl:template match="/">
- <!--make sure that this transformation is performed on a schema v18 model-->
- <xsl:if test="not(contains(/*[local-name() = 'project']/@xsi:schemaLocation, 'http://www.developer.cognos.com/schemas/bmt/18')) ">
- <xsl:message terminate="yes">The input file for this transformer must be a schema v18 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 v19 version-->
- <xsl:template match="*[local-name()='project'] ">
- <xsl:element name="project" namespace="http://www.developer.cognos.com/schemas/bmt/19/0">
- <xsl:for-each select="@*">
- <xsl:choose>
- <!--change schema from v18 to v19-->
- <xsl:when test="name(.) = 'xsi:schemaLocation'">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="'http://www.developer.cognos.com/schemas/bmt/19/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>
- <!-- Centralize data sources -->
- <xsl:variable name="dataSourceGroup">
- <sources>
- <xsl:for-each select="//*[local-name() = 'source'] ">
- <xsl:if test="string(*[local-name()='database'])">
- <xsl:variable name="srcKey" select="concat(*[local-name()='database'], ':', *[local-name()='catalog'], ':', *[local-name()='schema'] )"/>
- <xsl:if test="generate-id() = generate-id ( key('DS_KEY', $srcKey) [1] )">
- <xsl:copy-of select="."/>
- </xsl:if>
- </xsl:if>
- </xsl:for-each>
- </sources>
- </xsl:variable>
- <xsl:template match="*[local-name()='dataSources']">
- <dataSources>
- <xsl:for-each select="xalan:nodeset($dataSourceGroup)/*/*[local-name()='source']">
- <dataSource>
- <name>
- <xsl:value-of select="concat('DS', position())"/>
- </name>
- <cmDataSource>
- <xsl:value-of select="*[local-name()= 'database']"/>
- </cmDataSource>
- <xsl:if test="*[local-name()= 'catalog']">
- <catalog>
- <xsl:value-of select="*[local-name()= 'catalog']"/>
- </catalog>
- </xsl:if>
- <xsl:if test="*[local-name()= 'schema']">
- <schema>
- <xsl:value-of select="*[local-name()= 'schema']"/>
- </schema>
- </xsl:if>
- <xsl:if test="*[local-name()= 'databaseType']">
- <type>
- <xsl:value-of select="*[local-name()= 'databaseType']"/>
- </type>
- </xsl:if>
- </dataSource>
- </xsl:for-each>
- </dataSources>
- </xsl:template>
- <!-- Remove sources from all query subjects -->
- <!-- Dropped as requested by Glen Seeds -->
- <!-- xsl:template match="*[local-name()='sources' ]"/-->
- <!-- Convert a string, removing leading and trailing whitespace and double quots-->
- <xsl:template name="Normalize">
- <xsl:param name="str"/>
- <xsl:variable name="noSpace" select="normalize-space($str)"/>
- <xsl:choose>
- <xsl:when test="starts-with($noSpace, '"') and substring($noSpace, string-length(), 1)='"' ">
- <xsl:value-of select="substring($str, 2, string-length()-2)"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$str"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!-- Generate data source reference based on database, catalog and schema -->
- <xsl:template name="GetDataSourceRef">
- <xsl:param name="db" select="*[local-name() = 'database']"/>
- <xsl:param name="cat" select="*[local-name() = 'catalog']"/>
- <xsl:param name="schema" select="*[local-name() = 'schema']"/>
- <xsl:variable name="srcKey">
- <xsl:text>[</xsl:text>
- <xsl:call-template name="Normalize">
- <xsl:with-param name="str" select="$db"/>
- </xsl:call-template>
- <xsl:text>.</xsl:text>
- <xsl:call-template name="Normalize">
- <xsl:with-param name="str" select="$cat"/>
- </xsl:call-template>
- <xsl:text>.</xsl:text>
- <xsl:call-template name="Normalize">
- <xsl:with-param name="str" select="$schema"/>
- </xsl:call-template>
- <xsl:text>]</xsl:text>
- </xsl:variable>
- <xsl:for-each select="xalan:nodeset($dataSourceGroup)/*/*[local-name()='source']">
- <xsl:variable name="dsKey">
- <xsl:text>[</xsl:text>
- <xsl:call-template name="Normalize">
- <xsl:with-param name="str" select="*[local-name()='database']"/>
- </xsl:call-template>
- <xsl:text>.</xsl:text>
- <xsl:call-template name="Normalize">
- <xsl:with-param name="str" select="*[local-name()='catalog']"/>
- </xsl:call-template>
- <xsl:text>.</xsl:text>
- <xsl:call-template name="Normalize">
- <xsl:with-param name="str" select="*[local-name()='schema']"/>
- </xsl:call-template>
- <xsl:text>]</xsl:text>
- </xsl:variable>
- <xsl:if test="$srcKey=$dsKey ">
- <xsl:value-of select="concat('[DS', position(), ']')"/>
- </xsl:if>
- </xsl:for-each>
- </xsl:template>
- <!-- Convert stored procedure and mdQuery to use data source reference -->
- <xsl:template match="*[local-name() = 'storedProcedure' or local-name() = 'mdQuery'] / *[local-name() = 'source' ]">
- <dataSourceRef>
- <xsl:text>[].[dataSources].</xsl:text>
- <xsl:call-template name="GetDataSourceRef"/>
- </dataSourceRef>
- <!-- put back the source as requested by Glen Seeds -->
- <source>
- <xsl:apply-templates/>
- </source>
- </xsl:template>
- <!--Convert dbQuery/sql to use data source reference -->
- <xsl:template match="* [local-name() = 'dbQuery' ]">
- <dbQuery>
- <xsl:for-each select="@*">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
- </xsl:for-each>
- <xsl:choose>
- <xsl:when test="*[local-name() = 'sql']/@type='cognos' ">
- <xsl:apply-templates select="*[local-name()='sources' or local-name()='genearateSQL']"/>
- <xsl:for-each select="*[local-name()='sql']">
- <sql type="{@type}">
- <xsl:for-each select="node()">
- <xsl:choose>
- <xsl:when test="local-name()='table' and not (contains(., '#')) ">
- <table>
- <xsl:variable name="dataSource">
- <xsl:call-template name="GetDataSourceRef">
- <xsl:with-param name="db" select="substring-before(., '.')"/>
- <xsl:with-param name="cat" select="substring-before(substring-after(., '.'), '.')"/>
- <xsl:with-param name="schema" select="substring-before(substring-after(substring-after(., '.'), '.'), '.')"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="string($dataSource)">
- <xsl:value-of select="$dataSource"/>
- </xsl:when>
- <xsl:otherwise>[DS1]</xsl:otherwise>
- </xsl:choose>
- <xsl:variable name="tbl" select="substring-after(substring-after(substring-after(., '.'), '.'), '.') "/>
- <xsl:choose>
- <xsl:when test="string($tbl)">
- <xsl:value-of select="concat('.', $tbl )"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="concat('.', .)"/>
- </xsl:otherwise>
- </xsl:choose>
- </table>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates select="."/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- </sql>
- </xsl:for-each>
- <xsl:apply-templates select="*[local-name()!='sources' and local-name()!='generateSQL' and local-name()!= 'sql']"/>
- </xsl:when>
- <xsl:otherwise>
- <dataSourceRef>
- <xsl:for-each select="*[local-name()='sources']/*[local-name()='source'][1]">
- <xsl:text>[].[dataSources].</xsl:text>
- <xsl:call-template name="GetDataSourceRef"/>
- </xsl:for-each>
- </dataSourceRef>
- <xsl:apply-templates/>
- </xsl:otherwise>
- </xsl:choose>
- </dbQuery>
- </xsl:template>
- </xsl:stylesheet>
|