<?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="width" select="400"/>
<xsl:param name="height" select="350"/>
<xsl:param name="placement" select="left"/>

<!-- Return delimeted string denoting the number of columns, legend width, and legend height of a legend image to generage for a given map image size, based on the desired placement of the map (above, below, right left) relative to the image. See properties.xml file. Delimeter is vertical bar: | -->
<xsl:template match="/">
	<xsl:apply-templates select="mapviewer/properties/image"/>
</xsl:template>

<xsl:template match="/mapviewer/properties/image/size">
	<xsl:for-each select="option">
		<xsl:variable name="theWidth">
			<xsl:value-of select="@width"/>
		</xsl:variable>
		<xsl:variable name="theHeight">
			<xsl:value-of select="@height"/>
		</xsl:variable>
		<xsl:choose>		
		<xsl:when test="$width = $theWidth and $height = $theHeight">
		 	<xsl:for-each select="printmap">
				<xsl:variable name="theMapPlacementImg">
					<xsl:value-of select="@placement"/>
				</xsl:variable>										
				<xsl:choose>
					<xsl:when test="$placement = $theMapPlacementImg">
						<xsl:choose>
							<xsl:when test="@legendextend">
								<xsl:value-of select="@legendextend"/>
								<text>|</text>
							</xsl:when>
							<xsl:otherwise>
								<text>false|</text>
							</xsl:otherwise>
						</xsl:choose>
						<xsl:choose>
						<xsl:when test="@legendcolumns">
								<xsl:value-of select="@legendcolumns"/>
								<text>|</text>
							</xsl:when>
							<xsl:otherwise>
								<text>1|</text>
							</xsl:otherwise>
						</xsl:choose>							
						<xsl:choose>
							<xsl:when test="@legendwidth">
								<xsl:value-of select="@legendwidth"/>
								<text>|</text>
							</xsl:when>
							<xsl:otherwise>
								<text>125|</text>
							</xsl:otherwise>
						</xsl:choose>							
						<xsl:choose>
							<xsl:when test="@legendheight">
								<xsl:value-of select="@legendheight"/>
								<text>|</text>
							</xsl:when>
							<xsl:otherwise>
								<text>300|</text>
							</xsl:otherwise>
						</xsl:choose>							
					</xsl:when>
				</xsl:choose>
			</xsl:for-each>
		</xsl:when>
		</xsl:choose>
	</xsl:for-each>
</xsl:template>

</xsl:stylesheet>