<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:zi="http://zero-install.sourceforge.net/2004/injector/interface"
		xmlns:g="http://gfxmonk.net/dist/0install"
		version="1.0">
	<xsl:output method="xml" encoding="utf-8" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
	<xsl:template match="/zi:interface">
		<html>
			<head>
				<title>
					<xsl:value-of select="zi:name"/>
				</title>
				<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen, projection"/>
				<style type="text/css">
					.inner {
						max-width:60em;
					}
					.post h1 {
						font-size:3em;
						margin-top:0.2em;
					}
					.post > h2 {
						margin-top:-0.4em;
						padding-left:0.5em;
						color:#999;
						font-size:1.4em;
						margin-bottom: 1.1em;
					}
					dl {
						margin-top: 1em;
					}
					dt {
						font-size:1.35em;
						border-bottom: 1px solid #ccc;
						margin-top:1.4em;
						margin-left:1em;
						margin-bottom:0.2em;
					}

					dd.description {
						margin-left:1.4em;
						margin-top:1em;
						padding: 1em;
						padding-top: 0.5em;
						padding-bottom: 1em;
						padding-left: 1em;
						border: 1px solid #ddd;
					}
					code {
						font-weight:bold;
						color:#666;
					}

					.chrome code, .chrome pre {
						color: #888;
						line-height: 1.2em;
						font-size:1.2em;
					}

					dd.description {
						background-color: #fafafa;
					}
					pre.description {
						border: none;
						background:none;
						margin:0;
					}
					pre {
						font-size:1.1em;
					}

					.website {
						padding-left: 2em;
						font-size: 0.7em;
						opacity: 0.6;
						float:right;
						position:relative;
						top:0.3em;
					}
					.website a {
						font-weight:normal;
					}

					img.icon {
						float:left;
						max-width:86px;
						max-height:86px;
						position:relative;
						bottom:20px;
						margin-bottom:-20px;
					}

					dd > p {
						margin:0;
						padding:0;
					}
					.version {
						font-size: 0.8em;
						padding-left:0.5em;
						opacity:0.5;
					}
					.yourinfo {
						color: #888;
						font-size:0.9em;
						margin-bottom: 0.2em;
					}

					tr, td, th {
						margin:0;
						padding:2px 10px;
						border: 1px solid #d6d6d6;
						border-left: none;
						border-bottom: none;
						text-align:center;
					}
					table {
						border: 1px solid #d6d6d6;
						border-top: none;
						border-right: none;
						margin-top: 1em;
						width:100%;
					}
					th {
						background-color: #e6e6e6;
						color: #888;
					}
					td {
						background-color: #f3f3f3;
						margin:0;
					}
					pre {
						margin: 10px;
						border: none;
						background:none;
					}
					code {
						font-weight:normal;
					}

					.chrome p.index {
						text-align:center;
						margin-top:3em;
					}
					.chrome .explanation {
						font-size: 1.2em;
						line-height: 1.2em;
						text-align:left;
						color:#bbb;
					}
					.chrome pre {
						margin:0;
						margin-left:1em;
					}

					div.what-is-this {
						clear:both;
						margin-left:1em;
						font-size:1.2em;

						background: #e8f5fc url('index/question-mark.png') no-repeat 13px 45%;
						border: 1px solid #bbc3d0;

						padding: 10px;
						padding-left: 65px;
						min-height:40px;
						-moz-border-radius: 10px;
						color:#555;
					}
					.what-is-this a{
						color: #333;
						text-decoration: underline;
						font-weight: normal;
					}

				</style>
				<script type="text/javascript" src="/js/analytics.js"></script>
			</head>
			<body>
				<div class="site">
					<div class="title">
						<div class="inner">
							<a href="/">
								<img src="../../img/header.gif" alt="GFX::Monk Home"/>
							</a>
						</div>
					</div>
					<div class="main">
						<div class="content">
							<div class="post inner">

								<xsl:variable name="icon-href" select="(zi:icon[@type='image/png'][1])/@href"/>
								<xsl:if test="$icon-href != ''">
									<img src="{$icon-href}" class="alpha icon" />
								</xsl:if>

								<h1><xsl:value-of select="zi:name"/></h1>
								<h2><xsl:value-of select='zi:summary'/></h2>

								<div class="what-is-this">This page is a <a href="http://0install.net/">zero-install</a> feed.
									If you don't know what that is or how to use it, you're in luck - see the
									<a href="#what-is-this">instructions at the bottom of this page</a>
								</div>


								<dl>
									<xsl:apply-templates mode="dl" select="*|@*"/>

									<dt>Required libraries</dt>
									<dd>
										<xsl:choose>
											<xsl:when test="//zi:requires">
												<p class="yourinfo">
													(Zero Install will automatically download any required libraries for you)
												</p>
												<ul>
													<xsl:for-each select="//zi:requires">
														<xsl:variable name="interface" select="@interface"/>
														<xsl:if test="not(preceding::zi:requires[@interface = $interface])">
															<li>
																<a>
																	<xsl:attribute name="href">
																		<xsl:value-of select="$interface"/>
																	</xsl:attribute>
																	<xsl:value-of select="$interface"/>
																</a>
															</li>
														</xsl:if>
													</xsl:for-each>
												</ul>
											</xsl:when>
											<xsl:otherwise>
												<p>This feed does not list any additional requirements.</p>
											</xsl:otherwise>
										</xsl:choose>
									</dd>


									<dt>Available versions</dt>
									<dd>
										<xsl:choose>
											<xsl:when test="//zi:implementation">
												<p class="yourinfo">
													(Zero Install will automatically download one of these versions for you)
											</p>
												<table cellpadding="0" cellspacing="0">
													<tr>
														<th>Version</th>
														<th>Released</th>
														<th>Stability</th>
														<th>Platform</th>
														<th>Download</th>
													</tr>
													<xsl:for-each select="//zi:implementation">
														<tr>
															<td>
																<xsl:value-of select="(ancestor-or-self::*[@version])[last()]/@version"/>
																<xsl:if test="(ancestor-or-self::*[@version])[last()]/@version-modifier">
																	<xsl:value-of select="(ancestor-or-self::*[@version])[last()]/@version-modifier"/>
																</xsl:if>
															</td>
															<td>
																<xsl:value-of select="(ancestor-or-self::*[@released])[last()]/@released"/>
															</td>
															<td>
																<xsl:value-of select="(ancestor-or-self::*[@stability])[last()]/@stability"/>
															</td>
															<td>
																<xsl:variable name="arch" select="(ancestor-or-self::*[@arch])[last()]/@arch"/>
																<xsl:choose>
																	<xsl:when test="$arch = &quot;*-src&quot;">Source code</xsl:when>
																	<xsl:when test="not($arch)">Any</xsl:when>
																	<xsl:otherwise>
																		<xsl:value-of select="$arch"/>
																	</xsl:otherwise>
																</xsl:choose>
															</td>
															<td>
																<xsl:for-each select=".//zi:archive"><a href="{@href}">Download</a> (<xsl:value-of select="@size"/> bytes)
																</xsl:for-each>
															</td>
														</tr>
													</xsl:for-each>
												</table>
												


											</xsl:when>
											<xsl:otherwise>
												<p>No versions are available for downlad.</p>
											</xsl:otherwise>
										</xsl:choose>
									</dd>


									<xsl:if test="//zi:implementation[last()]/preceding-sibling::zi:environment[@name]">
										<dt>Affects environment</dt>
										<dd>
											<p class="yourinfo">
												(as of version <xsl:value-of select="//zi:implementation[last()]/@version"/>)
											</p>
											<ul>
												<xsl:for-each select="//zi:implementation[last()]/preceding-sibling::zi:environment[@name]">
													<li><xsl:value-of select="@name"/></li>
												</xsl:for-each>
											</ul>
										</dd>
									</xsl:if>



								</dl>
							</div>
						</div>
						<div class="clear"/>
					</div>
					<div class="chrome">
						<div class="inner">


								<div class="explanation">
									<a name="what-is-this"></a>
									<h3>What is this page, and how do I use it?</h3>
									<xsl:choose>
										<xsl:when test="//zi:implementation[@main] | //zi:group[@main] | //zi:command[@name='run']">

											<p>This is a runnable Zero Install feed. To add this program to your Applications menu, choose
												<b>Zero Install -&gt; Add New Program</b> from the <b>Applications</b> menu, and drag this
												feed's URL into the window it opens.
												If you don't see this menu item, install the <code>zeroinstall-injector</code> package from your
												distribution's repository, or from <a href="http://0install.net/injector.html">0install.net</a>.
											</p>
											<p>Alternatively, to run it from the command-line:<br/>
											<pre>0launch <xsl:value-of select="/zi:interface/@uri"/></pre>
											</p>
											<p>
												The <code>0alias</code> command can be used to create a short-cut to run it again later.
												If you don't have the <code>0launch</code> command, download it from
											<a href="http://0install.net/injector.html">0install.net</a>, which also contains
											documentation about how the Zero Install system works.</p>

										</xsl:when>
										<xsl:otherwise>

											<p>This is a Zero Install feed.
											This software cannot be run as an application directly. It is a library for other programs to use.</p>
											<p>For more information about using Zero Install packages, see the <a href="http://0install.net/dev.html">0install.net developer's guide</a>.</p>

										</xsl:otherwise>
									</xsl:choose>
									<a href="#">back to top.</a>
								</div>


							<p class="index">
								<strong>Note:</strong> You can see all available applications on my <a href="index/">0install index page</a>
							</p>
						</div>
					</div>
				</div>
				<div class="clear"/>
				<div class="inner footer">
				</div>
			</body>
		</html>
	</xsl:template>




	<xsl:template mode="dl" match="/zi:interface/@uri">
		<dt>Full URL</dt>
		<dd>
			<p>
				<a href="{.}">
					<xsl:value-of select="."/>
				</a>
			</p>
		</dd>
	</xsl:template>
	<xsl:template mode="dl" match="zi:homepage">
		<dt>Homepage</dt>
		<dd>
			<p>
				<a href="{.}">
					<xsl:value-of select="."/>
				</a>
			</p>
		</dd>
	</xsl:template>

	<!-- testing -->
	<xsl:template mode="dl" match="g:rich-description">
		<xsl:if test="normalize-space(.)">
			<dt>Description</dt>
			<dd class="description">
				<xsl:copy-of select="child::node()" />
			</dd>
		</xsl:if>
	</xsl:template>

	<xsl:template mode="dl" match="zi:description">
		<xsl:if test="normalize-space(.) and not(normalize-space(../g:rich-description))">
			<dt>Description</dt>
			<dd class="description">
				<pre class="description">
					<xsl:value-of select="."/>
				</pre>
			</dd>
		</xsl:if>
	</xsl:template>

	<!-- <xsl:template mode="dl" match="zi:icon"> -->
	<!-- 	<dt>Icon</dt> -->
	<!-- 	<dd> -->
	<!-- 		<p> -->
	<!-- 			<img src="{@href}" class="alpha"/> -->
	<!-- 		</p> -->
	<!-- 	</dd> -->
	<!-- </xsl:template> -->
	<xsl:template mode="dl" match="*|@*"/>
	<xsl:template match="zi:group">
		<dl class="group">
			<xsl:apply-templates mode="attribs" select="@stability|@version|@id|@arch|@released"/>
			<xsl:apply-templates select="zi:group|zi:requires|zi:implementation"/>
		</dl>
	</xsl:template>
	<xsl:template match="zi:requires">
		<dt>Requires</dt>
		<dd>
			<a href="{@interface}">
				<xsl:value-of select="@interface"/>
			</a>
		</dd>
	</xsl:template>
	<xsl:template match="zi:implementation">
		<dl class="impl">
			<xsl:apply-templates mode="attribs" select="@stability|@version|@id|@arch|@released"/>
			<xsl:apply-templates/>
		</dl>
	</xsl:template>
	<xsl:template mode="attribs" match="@*">
		<dt>
			<xsl:value-of select="name(.)"/>
		</dt>
		<dd>
			<xsl:value-of select="."/>
		</dd>
	</xsl:template>
	<xsl:template match="zi:archive">
		<dt>Download</dt>
		<dd><a href="{@href}"><xsl:value-of select="@href"/></a>
		(<xsl:value-of select="@size"/> bytes)</dd>
	</xsl:template>
</xsl:stylesheet>

