123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?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 17-->
- <!--XSL Transformation from a schema v17 model to a valid BMT schema v18 model-->
- <xsl:stylesheet xmlns="http://www.developer.cognos.com/schemas/bmt/18/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"/>
- <xsl:key name="FOLDER_KEY" match="*[local-name()='logicalModel' or local-name() = 'folder' or local-name() = 'queryItemFolder' ]" use="*[local-name()='name']"/>
- <!--root match-->
- <xsl:template match="/">
- <!--make sure that this transformation is performed on a schema v17 model-->
- <xsl:if test="not(contains(/*[local-name() = 'project']/@xsi:schemaLocation, 'http://www.developer.cognos.com/schemas/bmt/17')) ">
- <xsl:message terminate="yes">The input file for this transformer must be a schema v17 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 v18 version-->
- <xsl:template match="*[local-name()='project'] ">
- <xsl:element name="project" namespace="http://www.developer.cognos.com/schemas/bmt/18/0">
- <xsl:for-each select="@*">
- <xsl:choose>
- <!--change schema from v17 to v18-->
- <xsl:when test="name(.) = 'xsi:schemaLocation'">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="'http://www.developer.cognos.com/schemas/bmt/18/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>
- <!-- change all existing folders to namespaces -->
- <xsl:template match="* [ local-name() = 'folder' ]">
- <namespace>
- <xsl:apply-templates/>
- </namespace>
- </xsl:template>
- <!-- populate shortcut/targetType -->
- <xsl:template match="*[local-name() = 'shortcut' ]">
- <shortcut>
- <xsl:apply-templates select="*"/>
- <xsl:variable name="folderRef" select="substring-before(substring-after(*[local-name()='refobj'], '['), ']')"/>
- <xsl:variable name="objRef" select="substring-before(substring-after(substring-after(*[local-name()='refobj'], '.'), '['), ']')"/>
- <targetType>
- <xsl:for-each select="key('FOLDER_KEY', $folderRef)">
- <xsl:choose>
- <xsl:when test="string($objRef)">
- <xsl:for-each select="*/*[local-name()='name' and .=$objRef]">
- <xsl:value-of select="local-name(..)"/>
- </xsl:for-each>
- </xsl:when>
- <xsl:otherwise>
- <xsl:choose>
- <xsl:when test="local-name()='folder'">namespace</xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="local-name()"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- </targetType>
- </shortcut>
- </xsl:template>
- <!-- fix reference to shortcuts which point to folder or logicalModel -->
- <xsl:template match="*[ local-name() = 'refobj' ]">
- <xsl:variable name="self" select="."/>
- <xsl:variable name="folderRef" select="substring-before(substring-after($self , '['), ']')"/>
- <xsl:variable name="objRef" select="substring-before(substring-after(substring-after($self , '.'), '['), ']')"/>
- <xsl:variable name="itemRef" select="substring-after(substring-after($self, '.'), '.')"/>
- <!--if it points to a shortcut and the shortcut point to a folder, change it -->
- <refobj>
- <xsl:choose>
- <!-- 3 parts ID -->
- <xsl:when test="string($itemRef)">
- <xsl:value-of select="$self"/>
- </xsl:when>
- <!-- 2 parts ID need to change for folderShortcut -->
- <xsl:when test="string($objRef)">
- <xsl:variable name="obj" select="key('FOLDER_KEY', $folderRef)/*[ *[local-name()='name' and .=$objRef] ]"/>
- <xsl:choose>
- <xsl:when test="local-name($obj)='shortcut' and not(contains($obj/*[local-name() = 'refobj'], '.' ) )">
- <xsl:value-of select="concat('[', $objRef, ']')"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$self"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <!-- 1 part ID, need to change for queryItemFolder if needed-->
- <xsl:otherwise>
- <xsl:variable name="folder" select="key('FOLDER_KEY', $folderRef)"/>
- <xsl:choose>
- <xsl:when test="local-name($folder) = 'queryItemFolder' ">
- <xsl:call-template name="UniqueQIFName">
- <xsl:with-param name="QIF" select="$folder"/>
- <xsl:with-param name="type" select=" 'REF' "/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$self"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </refobj>
- </xsl:template>
- <!-- fix references to items in reserved collectors -->
- <xsl:template match="*[ local-name()= 'viewref' ]">
- <viewref>
- <xsl:value-of select="concat('[].', .)"/>
- </viewref>
- </xsl:template>
- <!-- Ensure quertyItemFolder name unique -->
- <xsl:template name="GetNewQIFName">
- <xsl:param name="serialNo" select=" '1' "/>
- <xsl:variable name="newName" select="concat(*[local-name()='name'], '~', $serialNo)"/>
- <xsl:choose>
- <xsl:when test="ancestor::*[local-name()='querySubject']//*[local-name() = 'queryItem' and *[local-name() ='name' and .=$newName]] ">
- <xsl:call-template name="GetNewQIFName">
- <xsl:with-param name="serialNo" select=" number($serialNo)+1 "/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$newName"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template name="UniqueQIFName">
- <xsl:param name="QIF" select="."/>
- <xsl:param name="type" select=" 'NAME' "/>
- <xsl:if test="$type='REF' ">[</xsl:if>
- <xsl:for-each select="$QIF">
- <xsl:variable name="name" select="*[local-name()='name']"/>
- <xsl:choose>
- <xsl:when test="ancestor::*[local-name()='querySubject']//*[local-name() = 'queryItem' and *[local-name() ='name' and .=$name]] ">
- <xsl:call-template name="GetNewQIFName"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$name"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- <xsl:if test="$type='REF' ">]</xsl:if>
- </xsl:template>
- <xsl:template match="* [ local-name() = 'queryItemFolder' ]">
- <queryItemFolder>
- <name locale="{*[local-name()='name']/@locale}">
- <xsl:call-template name="UniqueQIFName"/>
- </name>
- <xsl:apply-templates select="*[local-name() != 'name']"/>
- </queryItemFolder>
- </xsl:template>
- </xsl:stylesheet>
|