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

    IBM Cognos Products: cpscrn


    (C) Copyright IBM Corp. 2005, 2011

    US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
-->
   <!--
	Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
	Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
   -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xts="http://developer.cognos.com/schemas/xts/" xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
	<xsl:variable name="config" select="/root/input[@name='configurationResponse']/config/param[@name='contentLocales']"/>
	<xsl:template match="/">
		<response>
			<fragment>
				<xsl:if test="/root/interactions/param[@name='formaction']='view' or /root/interactions/param[@name='formaction']='save' or /root/interactions/param[@name='formaction']='cancel'">
					<xsl:if test="/root/interactions/param[@name='formaction']!='view'">
						<newMode>view</newMode>
					</xsl:if>					
				</xsl:if>
			</fragment>
			<xsl:if test="/root/interactions/param[@name='formaction']='save' and /root/controllerParams/param[@name='frag-mode']='edit'">
				<customs>
					<xsl:for-each select="/root/fragment/meta/customProperties">
						<xsl:choose>
							<xsl:when test="not(@name='LocaleSelect')">
								<xsl:variable name="cpName" select="@name"/>
								<param name="{$cpName}">
								<xsl:for-each select="$config/locale">
									<xsl:variable name="lid" select="@id"/>
									<xsl:for-each select="/root/interactions/param[@name = concat($cpName,'-',$lid)]">
										<xsl:if test="not(contains(string(/root/interactions/param[@name='removeLang']),concat($lid,';')))">
											<value xml:lang="{$lid}"><xsl:value-of select="string(.)"/></value>
										</xsl:if>
									</xsl:for-each>
								</xsl:for-each>
								</param>
							</xsl:when>
							<xsl:otherwise>
								<param name="LocaleSelect"><xsl:value-of select="/root/customs/param[@name='LocaleSelect']"/></param>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:for-each>
				</customs>
			</xsl:if>
		</response>
	</xsl:template>
	<xsl:template match="param" mode="state">
		<xsl:if test="/root/input[@name='stateParams']/stateParams/param[@name=current()/@name]">
			<xsl:copy-of select="."/>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>