123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- 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.
- -->
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fmfunc="http://www.developer.cognos.com/bmt" exclude-result-prefixes="fmfunc">
- <xsl:include href="fmmd_UpgradeStringResources.xsl"/>
- <xsl:output encoding="utf-8" method="xml" indent="yes"/>
- <!-- Template: Verify the schema # -->
- <xsl:template match="/">
- <!-- Make sure that this transformation is performed on a model using the old schema -->
- <xsl:variable name="inputNamespace" select="/*[local-name() = 'project']/@xsi:schemaLocation"/>
- <xsl:if test="not(contains($inputNamespace, concat('http://www.developer.cognos.com/schemas/bmt/', $nOldSchema))) ">
- <xsl:message terminate="yes">
- <xsl:value-of select="concat('The namespace of the model to be upgraded "', $inputNamespace, '" does not contain the expected schema number (', $nOldSchema, ').')"/>
- </xsl:message>
- </xsl:if>
- <xsl:apply-templates select="node()"/>
- </xsl:template>
- <!-- Template: General copy. Fix to prevent improper escaping of CDATA (should be copied over as is)-->
- <!--
- <xsl:template match="value/text()">
- <xsl:if test="name(.) = 'cdata'">
- <xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
- <xsl:value-of disable-output-escaping="yes" select="."/>
- <xsl:text disable-output-escaping="yes">]]></xsl:text>
- </xsl:if>
- <xsl:if test="not(name(.) = 'cdata')">
- <xsl:value-of disable-output-escaping="no" select="."/>
- </xsl:if>
- </xsl:template>
- -->
- <!-- Template: General copy for comments and processing instructions -->
- <xsl:template name="copyText" match="text() | comment() | processing-instruction()">
- <xsl:copy>
- <xsl:apply-templates select="@*|*"/>
- </xsl:copy>
- </xsl:template>
- <!-- Template: General copy -->
- <xsl:template match="*">
- <xsl:element name="{local-name(.)}" namespace="{$sEmptyNamespace}">
- <xsl:for-each select="@*">
- <xsl:attribute name="{local-name(.)}"><xsl:value-of select="."/></xsl:attribute>
- </xsl:for-each>
- <xsl:apply-templates select="node()"/>
- </xsl:element>
- </xsl:template>
- <!-- Template: Copy the current context's element tree -->
- <xsl:template name="myCopy">
- <xsl:param name="elemName">
- <xsl:value-of select="local-name(.)"/>
- </xsl:param>
- <xsl:choose>
- <xsl:when test="self::text()">
- <xsl:call-template name="copyText"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:element name="{$elemName}" namespace="{$sEmptyNamespace}">
- <xsl:for-each select="@*">
- <xsl:attribute name="{local-name(.)}"><xsl:value-of select="."/></xsl:attribute>
- </xsl:for-each>
- <xsl:apply-templates select="./node()"/>
- </xsl:element>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!-- Template: Copy the current context's attributes over -->
- <xsl:template name="myCopyAttributes">
- <xsl:for-each select="@*">
- <xsl:attribute name="{local-name(.)}"><xsl:value-of select="."/></xsl:attribute>
- </xsl:for-each>
- </xsl:template>
- <!-- Template: Annotate the given value -->
- <xsl:template name="annotate">
- <xsl:param name="value"/>
- <xsl:comment>
- <xsl:value-of select="$value"/>
- </xsl:comment>
- </xsl:template>
- <!-- Template: Helper function to find a single occurence of a delimited string-->
- <xsl:template name="substring-findDelimited">
- <xsl:param name="strString"/>
- <xsl:param name="strLeftDelimiter"/>
- <xsl:param name="strRightDelimiter"/>
- <xsl:value-of select="substring-before(substring-after($strString, $strLeftDelimiter), $strRightDelimiter)"/>
- </xsl:template>
- <!-- Template: Helper function to find and replace all occurences of a given delimited string. NOTE: Delimiters are included in the replacement -->
- <xsl:template name="substring-replaceDelimited">
- <xsl:param name="strString"/>
- <xsl:param name="strLeftDelimiter"/>
- <xsl:param name="strRightDelimiter"/>
- <xsl:param name="strReplace"/>
- <xsl:variable name="strMatch">
- <xsl:call-template name="substring-findDelimited">
- <xsl:with-param name="strString" select="$strRightMatch"/>
- <xsl:with-param name="strLeftDelimiter" select="$strLeftDelimiter"/>
- <xsl:with-param name="strRightDelimiter" select="$strRightDelimiter"/>
- <xsl:with-param name="strReplace" select="$strReplace"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="strMatchDelimited" select="concat($strLeftDelimiter, $strMatch, $strRightDelimiter)"/>
- <xsl:choose>
- <xsl:when test="contains($strString, $strMatchDelimited)">
- <xsl:variable name="strLeftMatch" select="substring-before($strString, $strLeftDelimiter)"/>
- <xsl:variable name="strRightMatch" select="substring-after(substring-after($strString, $strLeftDelimiter), $strRightDelimiter)"/>
- <xsl:value-of select="concat($strLeftMatch, $strReplace)"/>
- <xsl:call-template name="substring-replaceDelimited">
- <xsl:with-param name="strString" select="$strRightMatch"/>
- <xsl:with-param name="strLeftDelimiter" select="$strLeftDelimiter"/>
- <xsl:with-param name="strRightDelimiter" select="$strRightDelimiter"/>
- <xsl:with-param name="strReplace" select="$strReplace"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$strString"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!-- Template: Helper function to find and replace all occurences of a given string -->
- <xsl:template name="substring-replace">
- <xsl:param name="strString"/>
- <xsl:param name="strFind"/>
- <xsl:param name="strReplace"/>
- <xsl:choose>
- <xsl:when test="contains($strString, $strFind)">
- <xsl:value-of select="concat(substring-before($strString, $strFind), $strReplace)"/>
- <xsl:call-template name="substring-replace">
- <xsl:with-param name="strString" select="substring-after($strString, $strFind)"/>
- <xsl:with-param name="strFind" select="$strFind"/>
- <xsl:with-param name="strReplace" select="$strReplace"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$strString"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!-- Template: Update the schema version-->
- <xsl:template match="/*[local-name()='project'] ">
- <xsl:element name="project" namespace="{$sEmptyNamespace}">
- <xsl:for-each select="@*">
- <xsl:choose>
- <!-- Update the schema # -->
- <xsl:when test="name(.) = 'xsi:schemaLocation'">
- <xsl:attribute name="{name(.)}"><xsl:value-of select="concat($sEmptyNamespace, ' 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 select="node()"/>
- </xsl:element>
- </xsl:template>
- <!-- Template: Given a model object, search the model for a relationship
- which uses it and return the other side of the relationship.
- -->
- <xsl:template name="resolveRelationshipReference">
- <xsl:param name="refObj"/>
- <xsl:variable name="relationship" select="key('relationship_using_leftright_refobj', $refObj)"/>
- <xsl:variable name="leftRefobj" select="string($relationship/*[local-name() = 'expression']/*[local-name() = 'refobj'][1])"/>
- <xsl:variable name="rightRefobj" select="string($relationship/*[local-name() = 'expression']/*[local-name() = 'refobj'][2])"/>
- <xsl:choose>
- <xsl:when test="$leftRefobj = $refObj">
- <xsl:value-of select="$rightRefobj"/>
- </xsl:when>
- <xsl:when test="$rightRefobj = $refObj">
- <xsl:value-of select="$leftRefobj"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$refObj"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!-- Template: Given a refobj to either a dimesion or a measure dimension,
- search the model for a scopeRelationship which uses it and return the other
- side of the scopeRelationship.
- -->
- <xsl:template name="resolveScopeRelationshipReference">
- <xsl:param name="refObj"/>
- <xsl:variable name="scopeRelationship" select="key('scopeRelationship_using_leftright_refobj', $refObj)"/>
- <xsl:variable name="leftRefobj" select="string($scopeRelationship/*[local-name() = 'left']/*[local-name() = 'refobj'])"/>
- <xsl:variable name="rightRefobj" select="string($scopeRelationship/*[local-name() = 'right']/*[local-name() = 'refobj'])"/>
- <xsl:choose>
- <xsl:when test="$leftRefobj = $refObj">
- <xsl:value-of select="$rightRefobj"/>
- </xsl:when>
- <xsl:when test="$rightRefobj = $refObj">
- <xsl:value-of select="$leftRefobj"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$refObj"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!-- Template: Return a localized string value given an ID and a locale. For now accept 4 replacement strings.
- -->
- <xsl:template name="getLocalizedString">
- <xsl:param name="stringID"/>
- <xsl:param name="localeVal"/>
- <xsl:param name="string1"/>
- <xsl:param name="string2"/>
- <xsl:param name="string3"/>
- <xsl:param name="string4"/>
- <xsl:param name="bLocalize" select="true()"/>
- <xsl:choose>
- <!-- xsl:use-when="function-available('fmfunc:GetLocalizedString')" -->
- <xsl:when test="$bLocalize">
- <!--
- <xsl:message>
- <xsl:value-of select="concat('Localized string[', $localeVal, ']: ', fmfunc:GetLocalizedString($stringID, $localeVal))"/>
- </xsl:message>
- -->
- <xsl:value-of select="fmfunc:GetLocalizedString($stringID, $localeVal, $string1, $string2, $string3, $string4)"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$stringID"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!-- Template: Set attribute/element values to lowercase
- -->
- <xsl:template name="lowercaseValues">
- <xsl:param name="nodeset" select="."/>
- <xsl:for-each select="$nodeset">
- <xsl:apply-templates select="." mode="lowercaseValues"/>
- </xsl:for-each>
- </xsl:template>
- <xsl:template match="*" mode="lowercaseValues">
- <xsl:element name="{local-name(.)}" namespace="{$sEmptyNamespace}">
- <xsl:apply-templates select="@*|node()" mode="lowercaseValues"/>
- </xsl:element>
- </xsl:template>
- <xsl:template match="text()" mode="lowercaseValues">
- <xsl:value-of select="translate(., $uppercase, $lowercase)"/>
- </xsl:template>
- <xsl:template match="@*" mode="lowercaseValues">
- <xsl:attribute name="{local-name(.)}"><xsl:value-of select="translate(., $uppercase, $lowercase)"/></xsl:attribute>
- </xsl:template>
- <!-- Template: Output a trace message for debugging purposes.
- -->
- <xsl:template name="TRACE">
- <xsl:param name="msg"/>
- <!-- xsl:use-when="function-available('fmfunc:GetDateTime')" -->
- <xsl:if test="$nDebug">
- <xsl:message>
- <xsl:value-of select="concat(fmfunc:GetDateTime(), ': ', $msg)"/>
- </xsl:message>
- </xsl:if>
- </xsl:template>
- <xsl:template name="TRACE_BEGIN">
- <xsl:param name="templateID"/>
- <xsl:param name="msg"/>
- <!-- xsl:use-when="function-available('fmfunc:GetDateTime')" -->
- <xsl:if test="$nDebug">
- <xsl:message>
- <xsl:value-of select="concat(fmfunc:GetDateTime(), ': ', $templateID, ' ', $msg)"/>
- </xsl:message>
- </xsl:if>
- </xsl:template>
- <xsl:template name="TRACE_END">
- <xsl:param name="templateID"/>
- <xsl:param name="timerID"/>
- <!-- xsl:use-when="function-available('fmfunc:GetDateTime')" -->
- <xsl:variable name="TRACE_STOP" select="fmfunc:TimerStop($timerID)"/>
- <xsl:if test="$templateID = $nDebug">
- <xsl:message>
- <xsl:value-of select="concat(fmfunc:GetDateTime(), ': ', $templateID, ' DONE in [', $TRACE_STOP, '] seconds. ')"/>
- </xsl:message>
- </xsl:if>
- </xsl:template>
- <!-- =============================================================================== -->
- <!-- Global variables: -->
- <!-- =============================================================================== -->
- <xsl:variable name="nDebug" select="false()"/>
- <xsl:variable name="nDebugTimer" select="0"/>
- <xsl:variable name="lowercase" select="string('abcdefghijklmnopqrstuvwxyz')"/>
- <xsl:variable name="uppercase" select="string('ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
- <xsl:variable name="defaultLocale" select="translate(/*[local-name()='project']/*[local-name()='defaultLocale'], $uppercase, $lowercase)"/>
- <xsl:key
- name="scopeRelationship_using_leftright_refobj"
- match="*[local-name() = 'scopeRelationship']"
- use="*[local-name() = 'left' or local-name() = 'right']/*[local-name() = 'refobj']"/>
- <xsl:key
- name="relationship_using_leftright_refobj"
- match="*[local-name() = 'relationship']"
- use="*[local-name() = 'left' or local-name() = 'right']/*[local-name() = 'refobj']"/>
- </xsl:stylesheet>
|