<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<xsl:import href="resource/style.xsl" />
	<xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />
	<xsl:template match="/report">
		<html>
			<head>
				<meta http-equiv="content-type" content="text/html; charset=utf-8" />
				<title>Report</title>
				<link rel="stylesheet" href="resource/style.css" text="text/css" />
				<link rel="stylesheet" href="resource/style_footer.css" text="text/css" />
				<style>
					.observation {
						border: 1px solid #000000;
						padding: 3px;
					}
					.cattitle {
						font-size: 100%;
						font-weight: bold;
						margin-bottom: 1em;
					}
					.imgborder {
						margin-right: 0.5em;
						margin-bottom: 0.5em;
					}
				</style>
			</head>
			<body class="bodystyle">
				<!-- PlugIn information -->
				<xsl:apply-templates select="Analyses/Analysis" />
			</body>
		</html>
	</xsl:template>

	<xsl:template match="Analyses/Analysis">
		<!-- Header information -->
		<xsl:call-template name="header" />
		<!-- Observation -->
		<xsl:for-each select="Observations/Observation">
			<div class="observation">
				<xsl:if test="title">
					<span class="cattitle">Observation: </span><xsl:value-of select="title" /><br />
				</xsl:if>
				<xsl:if test="Description">
					<span class="cattitle">Description: </span><br />
					<pre style="display:inline; white-space:pre-wrap; word-wrap:break-word; word-break:break-all"><xsl:value-of select="Description" /></pre><br />
				</xsl:if>
				<xsl:if test="count(Images/*)&gt;=1">
					<xsl:apply-templates select="Images"/>
				</xsl:if>
			</div>
			<br />
			<xsl:if test="position()&lt;last()">
				<xsl:call-template name="footer" />
				<div class="reportpaging"><br /></div>
				<xsl:call-template name="header" />
			</xsl:if>
		</xsl:for-each>
		<!-- Footer information -->
		<xsl:call-template name="footer" />
	</xsl:template>

	<xsl:template match="Images">
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td align="top" rowspan="3">
					<img class="imgborder">
						<xsl:attribute name="src">
							<xsl:value-of select="Image[1]/@src" />
						</xsl:attribute>
						<xsl:attribute name="width">
							<xsl:value-of select="340" />
						</xsl:attribute>
					</img>
				</td>
			</tr>
			<xsl:for-each select="Image">
				<xsl:if test="position()&gt;=2 and position()&lt;=3">
					<tr><td>
					<img class="imgborder">
						<xsl:attribute name="src">
							<xsl:value-of select="@src" />
						</xsl:attribute>
						<xsl:attribute name="width">
							<xsl:value-of select="170" />
						</xsl:attribute>
					</img>
					</td></tr>
				</xsl:if>
			</xsl:for-each>
		</table>
		<xsl:for-each select="Image">
			<xsl:if test="position()&gt;=4">
				<img class="imgborder">
					<xsl:attribute name="src">
						<xsl:value-of select="@src" />
					</xsl:attribute>
					<xsl:attribute name="width">
						<xsl:value-of select="170" />
					</xsl:attribute>
				</img>
				<xsl:if test="(position() - 3) mod 3 = 0">
					<br />
				</xsl:if>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>

	<xsl:template name="header">
		<div align="left">
			<span class="maintitle"><xsl:value-of select="/report/Analyses/Analysis/@diplayname" /> report</span><br/>
			<img width="650" src="resource/header.bmp" />
		</div>
		<br />
		<!-- Patient information -->
		<xsl:call-template name="patient" />
	</xsl:template>

	<xsl:template name="patient">
		<table width="100%" cellpadding="0" cellspacing="0" class="withborder">
			<tr>
				<th width="13%">Patient name</th>
				<td width="20%"><xsl:value-of select="/report/SubjectContext/Name" /></td>
				<th width="10%">Patient ID</th>
				<td width="20%"><xsl:value-of select="/report/SubjectContext/ID" /></td>
				<th width="10%">Age</th>
				<td width="9%"><xsl:apply-templates select="/report/SubjectContext/Age" /></td>
				<th width="10%">Sex</th>
				<td width="8%"><xsl:apply-templates select="/report/SubjectContext/Sex" /></td>
			</tr>
			<tr>
				<th>Birth date</th>
				<td><xsl:apply-templates select="/report/SubjectContext/BirthDate" /></td>
				<th>Study date</th>
				<td><xsl:apply-templates select="/report/ProcedureContext/StudyDate" /></td>
				<xsl:if test="string-length(/report/ProtocolContext/ContrastAgent)!=0">
					<th>Contrast agent</th>
					<td colspan="3"><xsl:value-of select="/report/ProtocolContext/ContrastAgent" /></td>
				</xsl:if>
			</tr>
			<tr>
				<th>Referring physician</th>
				<td><xsl:apply-templates select="/report/ObserverContext/ReferringPhysician" /></td>
				<th>Reading physician</th>
				<td><xsl:apply-templates select="/report/ObserverContext/ReadingPhysician" /></td>
				<th>Performing physician</th>
				<td colspan="3"><xsl:apply-templates select="/report/ObserverContext/PerformingPhysician" /></td>
			</tr>
		</table>
		<br />
	</xsl:template>
</xsl:stylesheet>
