<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet version="1.0" 
	xmlns		= "http://www.w3.org/1999/xhtml"
	xmlns:h		= "http://www.w3.org/1999/xhtml"
	xmlns:xsl	= "http://www.w3.org/1999/XSL/Transform"
	xmlns:xsi	= "http://www.w3.org/2001/XMLSchema-instance"
	xmlns:rdf	= "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns:rdfs	= "http://www.w3.org/2000/01/rdf-schema#"
	xmlns:rss	= "http://purl.org/rss/1.0/"
	xmlns:cc	= "http://web.resource.org/cc/"
	xmlns:dc	= "http://purl.org/dc/elements/1.0/"
	xmlns:dcterms	= "http://purl.org/dc/terms/"
	xmlns:dcq	= "http://purl.org/metadata/dublin_core_qualifiers#"
	xmlns:hr	= "http://www.w3.org/2000/08/w3c-synd/#"
	xmlns:date	= "http://exslt.org/dates-and-times"
	xmlns:foaf	= "http://xmlns.com/foaf/0.1/"
	xmlns:rel	= "http://purl.org/vocab/relationship"
	xmlns:admin	= "http://webns.net/mvcb/"
	xmlns:svg	= "http://www.w3.org/2000/svg"
	xmlns:inkscape	= "http://www.inkskape.org/namespace/inkscape"
	xmlns:sodipodi	= "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
	xmlns:xlink	= "http://www.w3.org/1999/xlink"
	exclude-result-prefixes="xsl h xsi sodipodi inkscape">
	

<xsl:output method="xml" indent="yes" encoding="utf-8"/>
<xsl:output doctype-public="-//W3C//DTD XHTML 1.1//EN"/>
<xsl:output doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/>
<!--
	List of possible doctypes:
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
	
	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
	<!DOCTYPE HTML PUBLIC  "-//IETF//DTD HTML Level 1//EN">
	<!DOCTYPE HTML PUBLIC  "-//IETF//DTD HTML 2.0//EN">
	<!DOCTYPE HTML PUBLIC  "-//Microsoft/DTD Microsoft Internet Explorer 3.01 HTML//EN">
	
	<!DOCTYPE HTML PUBLIC "ISO/IEC 15445:2000//DTD HyperText Markup Language//EN">
	<!DOCTYPE HTML PUBLIC "ISO/IEC 15445:2000//DTD HTML//EN">
	(see: https://www.cs.tcd.ie/15445/UG.html)
	
-->
	
<xsl:param name="STYLESCRIPT" select="'no'"/>
<xsl:variable name="DIR" select="substring-before(/h:html/h:head/h:link[@rel='top']/@href, 'index')"/>
<xsl:variable name="DST" select="/h:html/h:head/h:link[@rel='this']/@href"/>
<xsl:param name="LANG"/>
<xsl:param name="BASE" select="'http://www.rorkvell.de'"/>
<xsl:param name="ENCODING" select="''"/>
<xsl:param name="IMGTYPE" select="'.png'"/>

<xsl:variable name="DSTTYPE">
	<xsl:choose>
		<xsl:when test="document('')/xsl:stylesheet/xsl:output/@method='xml'">
			<xsl:text>xhtml</xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="document('')/xsl:stylesheet/xsl:output/@method"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:variable>

<xsl:variable name="STYLE_TYPE">
<!--	<xsl:choose>
		<xsl:when test="document('')/xsl:stylesheet/xsl:output/@method='xml'">
			<xsl:text>XML_STYLE</xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<xsl:text>HTML_STYLE</xsl:text>
		</xsl:otherwise>
	</xsl:choose>
-->
	<xsl:text>HTML_STYLE</xsl:text>
</xsl:variable>
<xsl:param name="ALT_STYLE">
	<xsl:choose>
		<xsl:when test="$DSTTYPE = 'xhtml'">
			<xsl:text>yes</xsl:text>
		</xsl:when>
		<xsl:when test="$DSTTYPE = 'html'">
			<xsl:text>no</xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<xsl:text>no</xsl:text>
		</xsl:otherwise>
	</xsl:choose>
</xsl:param>

<xsl:include href="style.xsl"/>
<xsl:include href="meta.xsl"/>
<xsl:include href="nav.xsl"/>		<!-- general navigational elements -->
<xsl:include href="ac.xsl"/>		<!-- access keypad -->
<!--<xsl:include href="autotag.xsl"/>-->

<xsl:template name="DSTEXT">
	<xsl:text>.</xsl:text>
	<xsl:value-of select="$DSTTYPE"/>
	<xsl:text>.</xsl:text>
	<xsl:value-of select="$LANG"/>
	<xsl:value-of select="$ENCODING"/>
</xsl:template>

<xsl:template name="DSTMIME">
	<xsl:choose>
		<xsl:when test="$DSTTYPE='html'">
			<xsl:text>text/html</xsl:text>
		</xsl:when>
		<xsl:when test="$DSTTYPE='xhtml'">
			<xsl:text>application/xhtml+xml</xsl:text>
		</xsl:when>
	</xsl:choose>
</xsl:template>

<!-- ============== Start ================================================ -->
<xsl:template match="/">
	<xsl:if test="$STYLE_TYPE = 'XML_STYLE'">
		<xsl:call-template name="XML_STYLE"/>
	</xsl:if>
	<xsl:apply-templates select="h:html"/>
</xsl:template>

<xsl:template match="h:html">
	<xsl:element name="html">
		<xsl:choose>
			<xsl:when test="$DSTTYPE='html'">
				<xsl:attribute name="lang">
					<xsl:value-of select="$LANG"/>
				</xsl:attribute>
			</xsl:when>
			<xsl:when test="$DSTTYPE='xhtml'">
				<xsl:attribute name="xml:lang">
					<xsl:value-of select="$LANG"/>
				</xsl:attribute>
			</xsl:when>
		</xsl:choose>
		<xsl:apply-templates select="h:head[@lang=$LANG]"/>
		<xsl:apply-templates select="h:body[@lang=$LANG]"/>
	</xsl:element>
</xsl:template>

<!-- ============== Head ================================================= -->
<xsl:template match="h:head">
	<xsl:copy>
		<xsl:attribute name="profile">
			<xsl:text>http://dublincore.org/documents/dcq-html/</xsl:text>
			<xsl:text> http://www.rorkvell.de/tech/dc</xsl:text>
			<xsl:text> http://www.rorkvell.de/tech/stdpage</xsl:text>
			<xsl:text> http://www.rorkvell.de/tech/stdnav</xsl:text>
		</xsl:attribute>
		<xsl:if test="$STYLE_TYPE = 'HTML_STYLE'">
			<xsl:call-template name="HTML_STYLE"/>
		</xsl:if>
		<xsl:apply-templates/>
		<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='this']"/>
		<xsl:apply-templates select="/h:html/h:head[@lang!=$LANG]/h:link[@rel='this']" mode="ALT_LANG"/>
		<xsl:apply-templates select="/h:html/h:head[@lang]/link[@rel='this']" mode="ALT_FILETYPE"/>
		<xsl:call-template name="METADATA"/>
		<xsl:apply-templates select="/h:html/h:head/h:link[@rel='this']" mode="ALT_HEADER"/>
		<xsl:if test="not(h:title)">
			<xsl:apply-templates select="/h:html/h:body[@lang=$LANG]/h:h1[1]" mode="HEAD"/>
		</xsl:if>
		<xsl:if test="$STYLESCRIPT = 'yes'">
			<xsl:element name="script">
				<xsl:attribute name="type"><xsl:text>text/javascript</xsl:text></xsl:attribute>
				<xsl:attribute name="src">
					<xsl:value-of select="$DIR"/>
					<xsl:text>styles.js</xsl:text>
				</xsl:attribute>
			</xsl:element>
		</xsl:if>
		<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:script"/>
	</xsl:copy>
</xsl:template>

<xsl:template match="h:img">
	<xsl:copy>
		<xsl:apply-templates select="@*"/>
		<xsl:if test="not(@alt)">
			<xsl:attribute name="alt">
				<xsl:text/>
			</xsl:attribute>
		</xsl:if>
	</xsl:copy>
</xsl:template>

<xsl:template match="h:div[@id='main']">
	<xsl:apply-templates select="./*"/>
</xsl:template>
<xsl:template match="h:div[@id='footer']"/>
<xsl:template match="h:div[@class='footer']"/>
<xsl:template match="h:div[@id='nav']"/>
<xsl:template match="h:div[@class='nav']"/>
<xsl:template match="h:h1"/>


<!-- ============== Body ================================================= -->
<xsl:template match="h:body">
	<xsl:copy>
<!-- head -->
		<xsl:element name="div">
			<xsl:attribute name="id">
				<xsl:text>banner</xsl:text>	<!-- was: header -->
			</xsl:attribute>
			<xsl:choose>
				<xsl:when test="h:h1">
					<xsl:apply-templates select="h:h1[1]" mode="BODY"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:title" mode="BODY"/>
				</xsl:otherwise>
			</xsl:choose>
<!-- skiplink and feed -->
			<xsl:element name="ul">
				<xsl:element name="li">
					<xsl:element name="a">
						<xsl:attribute name="id">
							<xsl:text>skiplink</xsl:text>
						</xsl:attribute>
						<xsl:attribute name="href">
							<xsl:text>#main</xsl:text>
						</xsl:attribute>
						<xsl:choose>
							<xsl:when test="$LANG='de'">
								<xsl:text>Inhalt</xsl:text>
							</xsl:when>
							<xsl:when test="$LANG='en'">
								<xsl:text>skip to content</xsl:text>
							</xsl:when>
							<xsl:otherwise>
								<xsl:text>Inhalt</xsl:text>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:element>
				</xsl:element>
				<xsl:apply-templates 
					select="/h:html/h:head[@lang=$LANG]/h:link[@rel='alternate'][@type='application/rss+xml']"
					mode="HEADNAVI"/>
			</xsl:element>
<!-- breadcrumb navi -->
			<xsl:if test="/h:html/h:head[@lang=$LANG]/h:link[@rel='top']">
				<xsl:element name="ul">
					<xsl:attribute name="class">
						<xsl:text>breadcrumb</xsl:text>
					</xsl:attribute>
					<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='top']" mode="HEADNAVI"/>
					<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='up']" mode="HEADNAVI"/>
					<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='this']" mode="HEADNAVI"/>
				</xsl:element>
			</xsl:if>
		</xsl:element>
<!-- naked day by http://naked.dustindiaz.com/ -->
		<xsl:if test="$NAKED = 'true'">
			<xsl:choose>
				<xsl:when test="$LANG = 'de'">
					<xsl:element name="h3">
						<xsl:text>Was ist mit dem Aussehen passiert?</xsl:text>
					</xsl:element>
					<xsl:element name="p">
						<xsl:text>Für mehr Informationen, warum die Stylesheets hier und heute entgernt wurden, siehe die</xsl:text>
						<xsl:element name="a">
							<xsl:attribute name="href">
								<xsl:text>http://naked.dustindiaz.com/</xsl:text>
							</xsl:attribute>
							<xsl:attribute name="title">
								<xsl:text>Web Standards Naked Day Host Website</xsl:text>
							</xsl:attribute>
							<xsl:attribute name="lang"><xsl:text>en</xsl:text></xsl:attribute>
							<xsl:attribute name="hreflang"><xsl:text>en</xsl:text></xsl:attribute>
							<xsl:text> Annual CSS Naked Day</xsl:text>
						</xsl:element>
						<xsl:text> website.</xsl:text>
					</xsl:element>
				</xsl:when>
				<xsl:otherwise>
					<xsl:element name="h3">
						<xsl:text>What happened to the design?</xsl:text>
					</xsl:element>
					<xsl:element name="p">
						<xsl:text>To know more about why styles are disabled on this website visit the</xsl:text>
						<xsl:element name="a">
							<xsl:attribute name="href">
								<xsl:text>http://naked.dustindiaz.com/</xsl:text>
							</xsl:attribute>
							<xsl:attribute name="title">
								<xsl:text>Web Standards Naked Day Host Website</xsl:text>
							</xsl:attribute>
							<xsl:text> Annual CSS Naked Day</xsl:text>
						</xsl:element>
						<xsl:text> website for more information.</xsl:text>
					</xsl:element>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:if>
<!-- navigation -->
		<xsl:element name="div">
			<xsl:attribute name="id">
				<xsl:text>navigation</xsl:text>		<!-- was: nav -->
			</xsl:attribute>
			<xsl:element name="ul">
				<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='top']" mode="MAIN_NAVI"/>
				<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='contents']" mode="MAIN_NAVI"/>
				<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='help']" mode="MAIN_NAVI"/>
				<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='chapter']" mode="MAIN_NAVI"/>
				<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='bookmark']" mode="MAIN_NAVI"/>
			</xsl:element> <!-- ul -->
			<xsl:if test="/h:html/h:head[@lang=$LANG]/h:link[@rel='section']">
				<xsl:element name="hr"/>
				<xsl:element name="ul">
					<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='section']" mode="MAIN_NAVI"/>
				</xsl:element>
			</xsl:if>
			<xsl:if test="/h:html/h:head[@lang=$LANG]/h:link[@rel='subsection']">
				<xsl:element name="hr"/>
				<xsl:element name="ul">
					<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='subsection']" mode="MAIN_NAVI"/>
				</xsl:element>
			</xsl:if>
			<xsl:if test="h:div[@id='navigation']">
				<xsl:element name="hr"/>
				<xsl:apply-templates select="h:div[@id='navigation']/*"/>
			</xsl:if>
			<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='start']" mode="PREV_NEXT"/>
			<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='prev']" mode="PREV_NEXT"/>
			<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='next']" mode="PREV_NEXT"/>
			<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='end']" mode="PREV_NEXT"/>
<!-- access keypad -->
<!--			<xsl:if test="/h:html/h:head[@lang=$LANG]/h:link[@rel='top']">-->
<!--				<xsl:call-template name="ACCESSKEY"/>-->
<!--			</xsl:if>-->
		</xsl:element>
<!-- main -->
		<xsl:element name="div">
			<xsl:attribute name="id">
				<xsl:text>main</xsl:text>
			</xsl:attribute>
			<xsl:apply-templates select="*[not(@id='navigation')]"/>
		</xsl:element> <!-- div#main -->
<!-- footer -->
		<xsl:element name="div">
			<xsl:attribute name="id">
				<xsl:text>contentinfo</xsl:text>	<!-- was: footer -->
			</xsl:attribute>
			<xsl:if test="h:div[@id='footer']">
				<xsl:apply-templates select="h:div[@id='footer']/*"/>
				<xsl:element name="hr"/>
			</xsl:if>
			<xsl:element name="ul">
				<xsl:attribute name="class">
					<xsl:text>meta</xsl:text>
				</xsl:attribute>
				<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:meta" mode="FOOTER_NAVI"/>
				<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link" mode="FOOTER_NAVI"/>
				<xsl:apply-templates select="/h:html/h:body[@lang=$LANG]/h:*[@class='vcard'][1]" mode="FOOTER_NAVI"/>
				<xsl:apply-templates 
					select="/h:html/h:head/h:link[@rel='this']"
					mode="ALT_FOOTER"/>
			</xsl:element>
			<!-- serial (forward/backward) navigation -->
<!--
			<xsl:if test="/h:html/h:head[@lang=$LANG]/h:link[@rel='start'] or
				/h:html/h:head[@lang=$LANG]/h:link[@rel='prev'] or
				/h:html/h:head[@lang=$LANG]/h:link[@rel='next'] or
				/h:html/h:head[@lang=$LANG]/h:link[@rel='last']">
				<xsl:element name="ul">
					<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='start']" mode="FOOTER_NAVI"/>
					<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='prev']" mode="FOOTER_NAVI"/>
					<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='next']" mode="FOOTER_NAVI"/>
					<xsl:apply-templates select="/h:html/h:head[@lang=$LANG]/h:link[@rel='last']" mode="FOOTER_NAVI"/>
				</xsl:element>
			</xsl:if>
-->
		</xsl:element> <!-- div#footer -->
	</xsl:copy>
</xsl:template>


<xsl:template match="h:title|h:h1" mode="BODY">
	<xsl:element name="h1">
		<xsl:attribute name="class">
			<xsl:text>DC.title</xsl:text>
		</xsl:attribute>
<!--		<xsl:value-of select="."/>-->
		<xsl:apply-templates/>
	</xsl:element>
</xsl:template>


<!-- ============== Attributes =========================================== -->
<xsl:template match="@lang">
	<xsl:choose>
		<xsl:when test="name(..)='head'"/>
		<xsl:when test="name(..)='body'"/>
		<xsl:otherwise>
			<xsl:choose>
				<xsl:when test="$DSTTYPE='xhtml'">
					<xsl:attribute name="xml:lang">
						<xsl:value-of select="."/>
					</xsl:attribute>
				</xsl:when>
				<xsl:otherwise>
					<xsl:copy/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="h:p[@class='code']|h:code[@class='listing']">
	<xsl:copy-of select="."/>
</xsl:template>

<xsl:template match="h:script">
	<xsl:copy>
		<xsl:apply-templates select="@*"/>
		<xsl:apply-templates select="node()"/>
		<xsl:comment/>
	</xsl:copy>
</xsl:template>

<xsl:template match="h:*">
	<xsl:copy>
		<xsl:apply-templates select="@*"/>
		<xsl:apply-templates select="node()"/>
	</xsl:copy>
</xsl:template>

<xsl:template match="@*">
	<xsl:copy/>
</xsl:template>

</xsl:stylesheet>