<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" exclude-result-prefixes="a xhtml dll"
	xmlns:a="http://materialeplatform.dk/xml/danLom"
	xmlns:dll="http://materialeplatform.dk/xml/danLomList"
	xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:output standalone="yes" omit-xml-declaration="yes" indent="no" method="xml"/>

	<xsl:template match="dll:lomlist" xmlns:a="http://materialeplatform.dk/xml/danLom">
		<div>
			<xsl:apply-templates select="a:lom"/>
		</div>
	</xsl:template>

	<xsl:template match="a:lom" xmlns:a="http://materialeplatform.dk/xml/danLom">
		<div class="mp-enkelt">
			<h3>M&#229;lgruppe</h3>
			<hr/>
			<p>
				<!-- START Maalgruppe -->
				<xsl:for-each
					select="./a:classification[a:purpose/a:value='laeringsmaal' and not(starts-with(a:taxon/a:id, 'ANDET'))]">
					<xsl:call-template name="listEmner"/>
				</xsl:for-each>
				<xsl:if test="count(./a:classification[a:purpose/a:value='laeringsmaal']) > 0">
					<br/>
				</xsl:if>

				<xsl:for-each select="./a:classification[a:purpose/a:value='emne']">
					<xsl:call-template name="listEmner"/>
				</xsl:for-each>
				<xsl:if test="count(./a:classification[a:purpose/a:value='emne']) > 0">
					<br/>
				</xsl:if>

				<xsl:for-each
					select="./a:classification[a:purpose/a:value='niveau'][not(starts-with(a:taxon/a:id,'FSK-KL'))]">
					<xsl:call-template name="listKlassetrin"/>
				</xsl:for-each>

				<xsl:for-each
					select="./a:classification[a:purpose/a:value='niveau'][starts-with(a:taxon/a:id,'FSK-KL')]">
					<xsl:call-template name="listFolkeskoleKlassetrin"/>
				</xsl:for-each>
				<xsl:if
					test="count(./a:classification[a:purpose/a:value='niveau'][starts-with(a:taxon/a:id,'FSK-KL')]) > 0">
					<br/>
				</xsl:if>

				<!-- SLUT Maalgruppe -->
			</p>

			<h3>Beskrivelse</h3>
			<hr/>
			<p>
				<strong>
					<xsl:value-of select="a:general/a:title"/>
				</strong>
				<br/>

				<xsl:if test="count(a:lifecycle/a:contribute[a:role/a:value='forfatter']) = 0"
					>Forfatter: N/A</xsl:if>
				<xsl:if test="count(a:lifecycle/a:contribute[a:role/a:value='forfatter']) = 1"
					>Forfatter: </xsl:if>
				<xsl:if test="count(a:lifecycle/a:contribute[a:role/a:value='forfatter']) > 1"
					>Forfattere: </xsl:if>
				<xsl:for-each select="a:lifecycle/a:contribute[a:role/a:value='forfatter']">
					<xsl:sort select="a:role/a:value"/>
					<xsl:call-template name="listForfattere"/>
				</xsl:for-each>
			</p>
			<xsl:for-each select="a:lifecycle/a:contribute">
				<xsl:sort select="a:role/a:value"/>
				<xsl:choose>
					<xsl:when test="a:role/a:value = 'udgiver'">
						<p class="minimal"> Udgiver: <xsl:value-of select="a:entity/a:lastname"/>
						</p>
					</xsl:when>
				</xsl:choose>
			</xsl:for-each>
			<p class="minimal"> Udgivelsesdato: <xsl:value-of
					select="a:lifecycle/a:contribute/a:date"/>
			</p>
		</div>
	</xsl:template>

	<!--#####################      FUNCTION 	#####################-->
	<xsl:template name="listEmner">
		<xsl:variable name="cId">
			<xsl:value-of select="./a:taxon/a:id"/>
		</xsl:variable>
		<xsl:variable name="cName">
			<xsl:value-of select="./a:taxon/a:name"/>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="starts-with($cId,'FSK-FM')">
				<xsl:value-of select="substring-after($cName, 'l - ')"/>
			</xsl:when>
			<xsl:when test="starts-with($cId,'MUS-KUN')">
				<xsl:value-of select="substring-after($cName, 'kultur - ')"/>
			</xsl:when>
			<xsl:when test="starts-with($cId,'MUS-NAT')">
				<xsl:value-of select="substring-after($cName, 'teknik - ')"/>
			</xsl:when>
			<xsl:when test="$cId='FSK'">
				<xsl:value-of select="$cName"/>
			</xsl:when>
			<xsl:when test="$cId='HF'">
				<xsl:value-of select="$cName"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="a:taxon/a:name"/>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:if test="not(position()=last())">, </xsl:if>
	</xsl:template>


	<!--#####################      FUNCTION 	#####################-->
	<xsl:template name="listLaeringsmaal">
		<xsl:value-of select="a:taxon/a:name"/>
		<br/>
	</xsl:template>


	<!--#####################      FUNCTION 	#####################-->
	<xsl:template name="listForfattere">
		<span class="nobr">
			<xsl:value-of select="a:entity/a:firstname"/>
			<xsl:text> </xsl:text>
			<xsl:value-of select="a:entity/a:lastname"/>
			<xsl:if test="not(position()=last())">, </xsl:if>
		</span>
	</xsl:template>

	<xsl:template name="listKlassetrin">
		<xsl:value-of select="a:entity/a:firstname"/>
		<xsl:text> </xsl:text>
		<xsl:value-of select="a:entity/a:lastname"/>
		<br/>
	</xsl:template>

	<!-- #####################      FUNCTION 	#####################-->
	<xsl:template name="listFolkeskoleKlassetrin">
		<xsl:if test="last()=1">
			<xsl:value-of select="./a:taxon/a:id"/>
		</xsl:if>
		<xsl:if test="not(last()=1)">
			<xsl:if test="position()=1"><xsl:value-of
					select="substring-after(./a:taxon/a:id, 'KL-')"/>.-</xsl:if>
			<xsl:if test="position()=last()"><xsl:value-of
					select="substring-after(./a:taxon/a:id, 'KL-')"/>. kl.</xsl:if>
		</xsl:if>
	</xsl:template>
	<!-- SLUT matplat-enkelt -->

</xsl:stylesheet>

