123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- <?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 1-->
- <!--XSL Transformation from a schema v1 model to a valid BMT schema v2 model-->
- <xsl:stylesheet xmlns="http://www.developer.cognos.com/schemas/bmt/2/0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bmtcr1="http://www.developer.cognos.com/schemas/bmt/01" exclude-result-prefixes="bmtcr1">
- <xsl:output encoding="utf-8" method="xml" indent="yes"/>
- <!--root match-->
- <xsl:template match="/">
- <!--make sure that this transformation is not performed on a schema v2 model-->
- <xsl:if test="/bmtcr1:project/@xsi:schemaLocation = 'http://www.developer.cognos.com/schemas/bmt/2/0 BMTModelSpecification.xsd'">
- <xsl:message terminate="yes">The input file for this transformer must be a schema v1 model. You tried to use a schema v2 model. Exiting...</xsl:message>
- </xsl:if>
- <xsl:apply-templates/>
- </xsl:template>
- <!--generic match, copies over the element unless it is redefined later in the file-->
- <xsl:template match="*">
- <xsl:element name="{name(.)}">
- <xsl:for-each select="@*">
- <xsl:choose>
- <!--Check if the value is group, which is now called folder-->
- <xsl:when test=". = 'group'">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="'folder'"/></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>
- <!--rename workspace to project, create some new mandatory elements for the schema v2, change the schema validator to the v2 version-->
- <xsl:template match="bmtcr1:workspace">
- <xsl:element name="project" namespace="http://www.developer.cognos.com/schemas/bmt/2/0">
- <xsl:for-each select="@*">
- <xsl:choose>
- <!--Check if the value is group, which is now called folder-->
- <xsl:when test=". = 'group'">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="'folder'"/></xsl:attribute>
- </xsl:when>
- <!--change schema from v1 to v2-->
- <xsl:when test="name(.) = 'xsi:schemaLocation'">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="'http://www.developer.cognos.com/schemas/bmt/2/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>
- <!--re-order the sub-elements-->
- <!--name goes in the front-->
- <xsl:apply-templates select="bmtcr1:name"/>
- <!--create some new mandatory elements for the schema v2-->
- <!--it should always be english (en_US)-->
- <xsl:element name="languages">
- <xsl:element name="language">
- <xsl:value-of select="'en_US'"/>
- </xsl:element>
- </xsl:element>
- <!--it should always be english (en_US)-->
- <xsl:element name="defaultLanguage">
- <xsl:value-of select="'en_US'"/>
- </xsl:element>
- <xsl:element name="templates"/>
- <!--process the rest of the elements from the schema v1-->
- <xsl:apply-templates select="bmtcr1:logicalModel"/>
- <!--create parameterMaps and securityViews-->
- <xsl:element name="parameterMaps"/>
- <xsl:element name="securityViews"/>
- <!--use the old name-->
- <xsl:apply-templates select="bmtcr1:deployments"/>
- </xsl:element>
- </xsl:template>
- <!--remove the language attribute-->
- <xsl:template match="bmtcr1:logicalModel">
- <xsl:element name="logicalModel">
- <xsl:for-each select="@*">
- <xsl:choose>
- <!--Check if the value is group, which is now called folder-->
- <xsl:when test=". = 'group'">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="'folder'"/></xsl:attribute>
- </xsl:when>
- <xsl:otherwise>
- <!--skip the language attribute-->
- <xsl:if test="not(name(.) = 'language')">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
- </xsl:if>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:template>
- <!--rename group to folder-->
- <xsl:template match="bmtcr1:group">
- <xsl:element name="folder">
- <xsl:for-each select="@*">
- <xsl:choose>
- <!--Check if the value is group, which is now called folder-->
- <xsl:when test=". = 'group'">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="'folder'"/></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>
- <!--rename queryObject to querySubject-->
- <xsl:template match="bmtcr1:queryObject">
- <xsl:element name="querySubject">
- <xsl:for-each select="@*">
- <xsl:choose>
- <!--Check if the value is queryObject, which is now called querySubject-->
- <xsl:when test=". = 'queryObject'">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="'querySubject'"/></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>
- <!--removing the element "type" from a queryObject-->
- <xsl:template match="bmtcr1:type">
- <xsl:if test="not(name(parent::*) = 'queryObject')">
- <xsl:element name="{name(.)}">
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:if>
- </xsl:template>
- <!--rename queryElement to queryItem-->
- <xsl:template match="bmtcr1:queryElement">
- <xsl:element name="queryItem">
- <xsl:for-each select="@*">
- <xsl:choose>
- <!--Check if the value is queryElement, which is now called queryItem-->
- <xsl:when test=". = 'queryElement'">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="'queryItem'"/></xsl:attribute>
- </xsl:when>
- <xsl:otherwise>
- <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- <!--remove language and characterSet and modify expression-->
- <xsl:for-each select="*">
- <xsl:if test="not(name(.) = 'language') and not(name(.) = 'characterSet') and not(name(.) = 'expression')">
- <xsl:element name="{name(.)}">
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:if>
- <!--sub-class expression into calculation-->
- <xsl:if test="name(.) = 'expression'">
- <xsl:element name="calculation">
- <xsl:element name="name"/>
- <xsl:element name="expression">
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:element>
- </xsl:if>
- </xsl:for-each>
- </xsl:element>
- </xsl:template>
- <!--removing the columns element from a sql, but keep the column sub-elements-->
- <xsl:template match="bmtcr1:columns">
- <xsl:choose>
- <xsl:when test="not(name(parent::*) = 'sql')">
- <xsl:element name="{name(.)}">
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!--removing the tables element from a sql, but keep the table sub-elements-->
- <xsl:template match="bmtcr1:tables">
- <xsl:choose>
- <xsl:when test="not(name(parent::*) = 'sql')">
- <xsl:element name="{name(.)}">
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!--if a dbQuery is found, that has a sibling modelQuery, then eat the dbQuery-->
- <xsl:template match="bmtcr1:dbQuery">
- <xsl:choose>
- <xsl:when test="../bmtcr1:modelQuery">
- <!--do nothing-->
- </xsl:when>
- <xsl:otherwise>
- <xsl:element name="dbQuery">
- <xsl:for-each select="@*">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
- </xsl:for-each>
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!--modify modelQuery so that it doesn't need a dbQuery sibling anymore-->
- <xsl:template match="bmtcr1:modelQuery">
- <xsl:element name="modelQuery">
- <xsl:for-each select="@*">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
- </xsl:for-each>
- <xsl:for-each select="../bmtcr1:dbQuery/bmtcr1:source">
- <xsl:element name="source">
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:for-each>
- <xsl:element name="sql">
- <xsl:for-each select="../bmtcr1:dbQuery/bmtcr1:sql">
- <xsl:for-each select="@*">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
- </xsl:for-each>
- <xsl:apply-templates/>
- </xsl:for-each>
- </xsl:element>
- <xsl:apply-templates/>
- <xsl:element name="filters"/>
- </xsl:element>
- </xsl:template>
- <!--rename queryElements_collection to queryItems_collection-->
- <xsl:template match="bmtcr1:queryElements">
- <xsl:element name="queryItems">
- <xsl:for-each select="@*">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
- </xsl:for-each>
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:template>
- <!--rename queryElements_collection to queryItems_collection-->
- <xsl:template match="bmtcr1:queryElements_collection">
- <xsl:element name="queryItems_collection">
- <xsl:for-each select="@*">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
- </xsl:for-each>
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:template>
- <!--rename association to relationship-->
- <xsl:template match="bmtcr1:association">
- <xsl:element name="relationship">
- <xsl:for-each select="@*">
- <xsl:choose>
- <!--Check if the value is association, which is now called relationship-->
- <xsl:when test=". = 'association'">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="'relationship'"/></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>
- <!--rename associationschortcut to relationshipshortcut-->
- <xsl:template match="bmtcr1:associationschortcut ">
- <xsl:element name="relationshipshortcut">
- <xsl:for-each select="@*">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
- </xsl:for-each>
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:template>
- <!--rename deployments to packages-->
- <xsl:template match="bmtcr1:deployments">
- <xsl:element name="packages">
- <xsl:for-each select="@*">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
- </xsl:for-each>
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:template>
- <!--rename deployment to package-->
- <xsl:template match="bmtcr1:deployment">
- <xsl:element name="package">
- <xsl:for-each select="@*">
- <xsl:choose>
- <!--Check if the value is group, which is now called folder-->
- <xsl:when test=". = 'group'">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="'folder'"/></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>
- <!--rename language="en" to language="en_US" for a "name" element-->
- <xsl:template match="bmtcr1:name">
- <xsl:element name="name">
- <xsl:for-each select="@*">
- <xsl:choose>
- <!--Check if the value is en, which is now called en_US-->
- <xsl:when test=". = 'en'">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="'en_US'"/></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>
- </xsl:stylesheet>
|