<?xml version="1.0" encoding="UTF-8"?>
<!--
 Licensed Materials - Property of IBM

 IBM Cognos Products: fmmd

 (C) Copyright IBM Corp. 2003, 2010

 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">
	<xsl:template match="*">
		<xsl:copy>
			<xsl:copy-of select="@*"/>
			<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>
	<xsl:template match="action">
		<xsl:if test="not(@type='Create' and inputparams/param[@seq='1']/value='14' and inputparams/param[@seq='2']/value='[].[parameterMaps]' )">
			<xsl:copy>
				<xsl:attribute name="seq"><xsl:value-of select="@seq"/></xsl:attribute>
				<xsl:attribute name="type"><xsl:choose><xsl:when test="@type='AddLanguage' ">AddLocale</xsl:when><xsl:otherwise><xsl:value-of select="@type"/></xsl:otherwise></xsl:choose></xsl:attribute>
				<xsl:variable name="action_type" select="@type"/>
				<xsl:for-each select="*">
					<xsl:choose>
						<xsl:when test="self::inputparams">
							<xsl:copy>
								<xsl:choose>
									<xsl:when test="$action_type='AddLocale' or $action_type='AddLanguage'">
										<param seq="1" type="stringCollection">
											<value>
												<xsl:value-of select="param[@seq='1']/value"/>
											</value>
										</param>
										<xsl:apply-templates select="param[@seq != '1']"/>
									</xsl:when>
									<xsl:when test="$action_type='CreateShortcut' or $action_type='LinkModel' or $action_type='ModelImport' ">
										<xsl:apply-templates select="*"/>
										<param seq="{count(param)+1}" type="integer">
											<value>1</value>
										</param>
									</xsl:when>
									<xsl:when test="$action_type='DBImport' ">
										<xsl:apply-templates select="param[@seq='1']"/>
										<param seq="2" type="{param[@seq='2']/@type}">
											<xsl:variable name="newValue">
												<xsl:call-template name="substring-replace">
													<xsl:with-param name="string">
														<xsl:apply-templates select="param[@seq='2']/value"/>
													</xsl:with-param>
													<xsl:with-param name="search">
														<xsl:text disable-output-escaping="yes">&lt;item Name="Procedures" Type="procedures" Value="true"/&gt;</xsl:text>
													</xsl:with-param>
													<xsl:with-param name="replace">
														<xsl:text disable-output-escaping="yes">&lt;item Name="Procedures" Type="procedures" Value="true"/&gt;&lt;item Name="Functions" Type="functions" Value="true"/&gt;</xsl:text>
													</xsl:with-param>
												</xsl:call-template>
											</xsl:variable>
											<value>
												<!--xsl:copy-of select="$myValue"/-->
												<xsl:value-of select="$newValue" disable-output-escaping="yes"/>
											</value>
										</param>
										<param seq="3" type="integer">
											<value>0</value>
										</param>
										<param seq="4" type="integer">
											<value>1</value>
										</param>
										<xsl:for-each select="param[@seq !='1' and @seq!= '2']">
											<param seq="{number(@seq)+2}" type="{@type}">
												<xsl:apply-templates/>
											</param>
										</xsl:for-each>
										<param seq="9" type="integer">
											<value>0</value>
										</param>
									</xsl:when>
									<xsl:when test="$action_type='FindOrCreateDataSource' ">
										<param seq="1" type="{param[@seq='5']/@type}">
											<xsl:apply-templates select="param[@seq='5']/value"/>
										</param>
										<xsl:for-each select="param[number(@seq) &lt; 4]">
											<param seq="{number(@seq)+1} " type="{@type}">
												<xsl:apply-templates/>
											</param>
										</xsl:for-each>
									</xsl:when>
									<xsl:when test="$action_type='ImportTranslations' ">
										<xsl:for-each select="*">
											<xsl:choose>
												<xsl:when test="self::param and @seq='3' ">
													<param seq="3" type="stringCollection">
														<value>
															<xsl:value-of select="value"/>
														</value>
													</param>
												</xsl:when>
												<xsl:otherwise>
													<xsl:copy-of select="."/>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:for-each>
									</xsl:when>
									<xsl:when test="$action_type='ExportTranslations' ">
										<xsl:for-each select="*">
											<xsl:choose>
												<xsl:when test="self::param and @seq='2' ">
													<param seq="2" type="stringCollection">
														<value>
															<xsl:value-of select="value"/>
														</value>
													</param>
												</xsl:when>
												<xsl:otherwise>
													<xsl:apply-templates select="."/>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:for-each>
									</xsl:when>
									<xsl:when test="$action_type='SegmentModel' ">
										<xsl:apply-templates select="*"/>
										<param seq="{count(param)+1}" type="i18nstring">
											<value/>
										</param>
									</xsl:when>
									<xsl:when test="$action_type='TransformRelationship' ">
										<xsl:for-each select="param">
											<xsl:choose>
												<xsl:when test="position() = last() -3">
													<param seq="{position()}" type="integer">
														<value>0</value>
													</param>
													<param seq="{position()+1}" type="integer">
														<value>1</value>
													</param>
													<param seq="{position()+2}" type="{@type}">
														<xsl:apply-templates/>
													</param>
												</xsl:when>
												<xsl:when test="position() > last() -3">
													<param seq="{number(@seq)+2}" type="{@type}">
														<xsl:apply-templates/>
													</param>
												</xsl:when>
												<xsl:otherwise>
													<xsl:apply-templates select="."/>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:for-each>
									</xsl:when>
									<xsl:when test="$action_type='ModifyComplex'">
										<xsl:apply-templates select="param[@seq='1']"/>
										<param seq="2" type="{param[@seq='2']/@type}"/>
										<xsl:variable name="newValue">
											<xsl:call-template name="substring-replace">
												<xsl:with-param name="string">
													<xsl:apply-templates select="param[@seq='2']/value"/>
												</xsl:with-param>
												<xsl:with-param name="search">
													<xsl:text disable-output-escaping="no">&lt;functionSetID&gt;</xsl:text>
												</xsl:with-param>
												<xsl:with-param name="replace">
													<xsl:text disable-output-escaping="no">&lt;functionSet&gt;&lt;functionSetID&gt;</xsl:text>
												</xsl:with-param>
											</xsl:call-template>
										</xsl:variable>
										<xsl:variable name="newValue2">
										<xsl:value-of select="$newValue"/>
											<xsl:call-template name="substring-replace">
												<xsl:with-param name="string" select="$newValue"/>
												<xsl:with-param name="search">
													<xsl:text disable-output-escaping="no">&lt;/functionSetID&gt;</xsl:text>
												</xsl:with-param>
												<xsl:with-param name="replace">
													<xsl:text disable-output-escaping="no">&lt;/functionSetID&gt;&lt;/functionSet&gt;</xsl:text>
												</xsl:with-param>
											</xsl:call-template>
										</xsl:variable>
										<value>
											<xsl:value-of select="$newValue2" disable-output-escaping="no"/>
										</value>
									</xsl:when>
									<xsl:otherwise>
										<xsl:apply-templates/>
									</xsl:otherwise>
								</xsl:choose>
							</xsl:copy>
						</xsl:when>
						<xsl:otherwise>
							<xsl:apply-templates select="."/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:for-each>
			</xsl:copy>
		</xsl:if>
	</xsl:template>
	<xsl:template match="value">
		<xsl:variable name="paramStr">
			<xsl:choose>
				<xsl:when test="contains(., '[].[parameterMaps].[governor]') or contains(., '[].[parameterMaps].[env]')">
					<xsl:call-template name="substring-replace">
						<xsl:with-param name="string">
							<xsl:call-template name="substring-replace">
								<xsl:with-param name="string" select="."/>
								<xsl:with-param name="search" select="'[].[parameterMaps].[governor]' "/>
								<xsl:with-param name="replace" select="'[].[parameterMaps].[_governor]' "/>
							</xsl:call-template>
						</xsl:with-param>
						<xsl:with-param name="search" select="'[].[parameterMaps].[env]' "/>
						<xsl:with-param name="replace" select="'[].[parameterMaps].[_env]' "/>
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="."/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:copy>
			<xsl:choose>
				<xsl:when test="../@type='cclnode' or ../@type='node' or ../@type='stringCollection' or ../@type='void' ">
					<xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
					<xsl:value-of select="$paramStr" disable-output-escaping="yes"/>
					<xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$paramStr"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:copy>
	</xsl:template>
	<xsl:template name="substring-replace">
		<xsl:param name="string"/>
		<xsl:param name="search"/>
		<xsl:param name="replace"/>
		<xsl:choose>
			<xsl:when test="contains($string, $search)">
				<xsl:value-of select="concat(substring-before($string, $search), $replace)"/>
				<xsl:call-template name="substring-replace">
					<xsl:with-param name="string" select="substring-after($string, $search)"/>
					<xsl:with-param name="search" select="$search"/>
					<xsl:with-param name="replace" select="$replace"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$string"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>