<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:output method="xml" indent="no"/>
	
<!-- LINKS COMPONENT -->	
	
	<xsl:template match="compkl">
		<table class="complist" xmlns="http://www.w3.org/1999/xhtml">
			<tr>
				<th><xsl:value-of select="title"/></th>
				<th class="detail">Type</th>
			</tr>
			
			<xsl:for-each select="site">
				
			<xsl:for-each select="document(concat('sit_xml.php?id=', @id))/site/course">
			<xsl:call-template name="kldetails"/>	
			</xsl:for-each>	
			
			<xsl:for-each select="document(concat('sit_xml.php?id=', @id))/site/contentobject">
			<xsl:call-template name="kldetails"/>	
			</xsl:for-each>	
			
			</xsl:for-each>		
			
			<xsl:for-each select="resource">
			
			<xsl:for-each select="document(concat('res_xml.php?id=', @id))/resource/document">
			<xsl:call-template name="kldetails"/>	
			</xsl:for-each>				
			
			<xsl:for-each select="document(concat('res_xml.php?id=', @id))/resource/flash">
			<xsl:call-template name="kldetails"/>	
			</xsl:for-each>			
			
			<xsl:for-each select="document(concat('res_xml.php?id=', @id))/resource/sound">
			<xsl:call-template name="kldetails"/>	
			</xsl:for-each>				
			
			<xsl:for-each select="document(concat('res_xml.php?id=', @id))/resource/image">
			<xsl:call-template name="kldetails"/>
			</xsl:for-each>				
			
			<xsl:for-each select="document(concat('res_xml.php?id=', @id))/resource/article">
			<xsl:call-template name="kldetails"/>	
			</xsl:for-each>		
			
			<xsl:for-each select="document(concat('res_xml.php?id=', @id))/resource/movie">
			<xsl:call-template name="kldetails"/>	
			</xsl:for-each>
			
			<xsl:for-each select="document(concat('res_xml.php?id=', @id))/resource/link">
			<xsl:call-template name="kldetails"/>	
			</xsl:for-each>		
		
			</xsl:for-each>
		</table>
	</xsl:template>
	
	<xsl:template name="kldetails">			
			<xsl:param name="filename">
			
			<xsl:choose>
				<xsl:when test="name() = 'movie'">
					<xsl:choose>
						<xsl:when test="lowres/filename/text()">
							<xsl:value-of select="lowres/filename"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="hires/filename"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="file/filename"/>
				</xsl:otherwise>
			</xsl:choose>
			
			</xsl:param>	
			<xsl:param name="iconname"><xsl:value-of select="substring-after($filename,'.')"/></xsl:param>
			<xsl:param name="icon"><xsl:value-of select="translate($iconname, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/></xsl:param>
		<tr xmlns="http://www.w3.org/1999/xhtml">
			<td>
				<xsl:choose>
				<xsl:when test="parent::resource">
				<xsl:choose>
				<xsl:when test="$icon">
				<img src="images/icon_{$icon}.gif" class="icon left" alt="-"/> 
				</xsl:when>
				<xsl:otherwise>
				<img src="images/icon_txt.gif" class="icon left" alt="-"/> 
				</xsl:otherwise>
				</xsl:choose>
				<a href="page_resource.php?pageID={$currentpage}&amp;resourceID={/resource/@id}"><h4><xsl:value-of select="../name"/></h4></a> 
					<div>
						<p class="detail"><xsl:value-of select="../description" disable-output-escaping="yes"/></p>	
						<xsl:if test="name() = 'link' or name() = 'course'">
						<p class="long"><a href="{url}"><xsl:value-of select="url"/></a></p>		
						</xsl:if>
						<p class="long">Open: <a href="page_resource.php?pageID={$currentpage}&amp;resourceID={/resource/@id}"><xsl:value-of select="../name"/></a></p>	
					</div>					
				</xsl:when>
				<xsl:otherwise>
				<a href="page_site.php?pageID={$currentpage}&amp;siteID={/site/@id}"><h4><xsl:value-of select="../name"/></h4></a>
					<div>
						<img src="{thumbnail/@filename}" class="loicon left detail" width="100" alt="-"/> 
						<p class="detail"><xsl:value-of select="../description" disable-output-escaping="yes"/></p>	
						<xsl:if test="name() = 'link' or name() = 'course'">
						<p class="long"><a href="{url}"><xsl:value-of select="url"/></a></p>		
						</xsl:if>
						<p class="long">Open: <a href="page_site.php?pageID={$currentpage}&amp;siteID={/site/@id}"><xsl:value-of select="../name"/></a></p>	
					</div>
				</xsl:otherwise>
				</xsl:choose>
			</td>		
			<xsl:choose>
			<xsl:when test="parent::resource">
			<td class="detail"><p class="type"><xsl:value-of select="name()"/></p><br/></td>
			</xsl:when>
			<xsl:otherwise>
			<td class="detail"><p class="type"><xsl:value-of select="@type"/></p><br/></td>
			</xsl:otherwise>
			</xsl:choose>	
		</tr> 
	</xsl:template>
	
</xsl:stylesheet>

