<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<!-- Map Viewer (Third Edition) by Howie Sternberg at howies@snet.net. Map Viewer is placed in the public domain and is "Freeware". Map Viewer may be freely used and redistributed, is provided "AS-IS" without warranty of any kind, and there is no technical support provided. --> 

<!-- input parameters and defauts --> 
<xsl:param name="currentMapServerUrl" select="'invalid'"/>
<xsl:param name="currentMapService" select="'invalid'"/>
<xsl:param name="currentMapTitle" select="'invalid'"/>

<!-- Return delimeted string of default setting for Layers function. See mapviewer.xml file. Delimeter is vertical bar | between layers and comma (,) between settings. -->
<xsl:template match="/">
<xsl:for-each select="mapviewer/servers/server/mapservices/mapservice/map">
	<xsl:variable name="mapServerUrl">
		<xsl:value-of select="../../../@url"></xsl:value-of>
	</xsl:variable>
	<xsl:variable name="mapService">
		<xsl:value-of select="../@name"></xsl:value-of>
	</xsl:variable>
	<xsl:variable name="mapTitle">
		<xsl:value-of select="@title"></xsl:value-of>
	</xsl:variable>
	<xsl:choose>
		<xsl:when test="$currentMapServerUrl = $mapServerUrl">
			<xsl:choose>
				<xsl:when test="$currentMapService = $mapService">
					<xsl:if test="$currentMapTitle = $mapTitle">
						<xsl:for-each select="layers/layer">								
							<xsl:if test="@id">
								<xsl:variable name="varCanDoVisible">
									<xsl:choose>
										<xsl:when test="@candovisible">
											<xsl:value-of select="@candovisible"/>
										</xsl:when>
										<xsl:otherwise>
											<text>false</text>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:variable>							
								<xsl:variable name="varCanDoLegend">
									<xsl:choose>
										<xsl:when test="@candolegend">
											<xsl:value-of select="@candolegend"/>
										</xsl:when>
										<xsl:otherwise>
											<text>false</text>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:variable>						
								<xsl:variable name="varCanDoIdentify">
									<xsl:choose>
										<xsl:when test="@candoidentify">
											<xsl:value-of select="@candoidentify"/>
										</xsl:when>
										<xsl:otherwise>
											<text>false</text>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:variable>
								<xsl:variable name="varCanDoSelect">
									<xsl:choose>
										<xsl:when test="@candoselect">
											<xsl:value-of select="@candoselect"/>
										</xsl:when>
										<xsl:otherwise>
											<text>false</text>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:variable>
								<xsl:variable name="varIsVisibleOn">
									<xsl:choose>
										<xsl:when test="@isvisibleon">
											<xsl:value-of select="@isvisibleon"/>
										</xsl:when>
										<xsl:otherwise>
											<text>false</text>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:variable>
								<xsl:variable name="varIsLegendOn">
									<xsl:choose>
										<xsl:when test="@islegendon">
											<xsl:value-of select="@islegendon"/>
										</xsl:when>
										<xsl:otherwise>
											<text>false</text>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:variable>
								<xsl:variable name="varIsIdentifyOn">
									<xsl:choose>
										<xsl:when test="@isidentifyon">
											<xsl:value-of select="@isidentifyon"/>
										</xsl:when>
										<xsl:otherwise>
											<text>false</text>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:variable>
								<xsl:variable name="varDefaultSelect">
									<xsl:choose>
										<xsl:when test="@defaultselect">
											<xsl:value-of select="@defaultselect"/>
										</xsl:when>
										<xsl:otherwise>
											<text>false</text>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:variable>
								<xsl:value-of select="@id"/>
								<text>,</text>							
								<xsl:value-of select="$varCanDoVisible"/>									
								<text>,</text>
								<xsl:value-of select="$varCanDoLegend"/>									
								<text>,</text>
								<xsl:value-of select="$varCanDoIdentify"/>									
								<text>,</text>
								<xsl:value-of select="$varCanDoSelect"/>									
								<text>,</text>
								<xsl:value-of select="$varIsVisibleOn"/>									
								<text>,</text>		
								<xsl:value-of select="$varIsLegendOn"/>
								<text>,</text>		
								<xsl:value-of select="$varIsIdentifyOn"/>
								<text>,</text>		
								<xsl:value-of select="$varDefaultSelect"/>
								<text>|</text>
							</xsl:if>
						</xsl:for-each>	
					</xsl:if>				
				</xsl:when>
			</xsl:choose>
		</xsl:when>
	</xsl:choose>			
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>