<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
	<xsl:output method="xml" version="1.0" encoding="utf-16" indent="yes" omit-xml-declaration="no"/>
-->
	<xsl:output method="html" version="4.0" encoding="utf-16" indent="yes" />

<!-- ================================================================================================== -->
<!-- Top Level																							-->
<!-- ================================================================================================== -->

<xsl:template match="/">
	<xsl:call-template name="Header"/>
	<xsl:apply-templates select="SR"/>
	<xsl:call-template name="Footer"/>
</xsl:template>

<!-- ================================================================================================== -->
<!-- dicom																								-->
<!-- ================================================================================================== -->

<xsl:template name="Header">
</xsl:template>

<xsl:template match="SR">
	<xsl:call-template name="GeneralAttributes"/>
	<xsl:apply-templates select="CONTAINER"/>
</xsl:template>

<xsl:template name="Footer">
	<hr/>
	<p align="center"><img border="0" src="Company.jpg" width="100" height="30"/></p>
</xsl:template>

<!-- ================================================================================== -->
<!--	General Attributes																-->
<!-- ================================================================================== -->

<xsl:template name="GeneralAttributes">
	<center>
		<font size="6">
		<xsl:value-of select="CONTAINER/@CM"/>
		</font>
	</center>
	<p/>
	<table width="100%">
		<tr>
			<th align="right">Patient Name: </th>
			<td><xsl:value-of select="Patient/@N"/></td>
			<th align="right">Completion Status: </th>
			<td><xsl:value-of select="Status/@C"/></td>
		</tr>
		<tr>
			<th align="right">Patient Id: </th>
			<td><xsl:value-of select="Patient/@I"/></td>
			<th align="right">Verification Status: </th>
			<td><xsl:value-of select="Status/@V"/></td>
		</tr>
		<tr>
			<th align="right">Study Date: </th>
			<td><xsl:value-of select="Study/@D"/></td>
			<th align="right">Verifier Name: </th>
			<td><xsl:value-of select="Verifier/@N"/></td>
		</tr>
		<tr>
			<th align="right">Accession Number: </th>
			<td><xsl:value-of select="Study/@A"/></td>
			<th align="right">Verification Date: </th>
			<td><xsl:value-of select="Verifier/@D"/></td>
		</tr>
	</table>
</xsl:template>

<!-- ================================================================================== -->
<!--	CONTAINER																		-->
<!-- ================================================================================== -->

<xsl:template match="CONTAINER">
	<p/>
	<dl>
	<dt>
		<span style="color:blue; font-size:large; font-style:italic; font-weight:bolder; text-decoration:underline">
		<xsl:call-template name="ConceptName"/>
		</span>
	</dt>
	<dd>
		<font size="-1">
		<xsl:apply-templates select="*[@R!='CONTAINS']"/>
		</font>
		<xsl:apply-templates select="*[@R='CONTAINS']"/>
	</dd>
	</dl>
</xsl:template>

<!-- ================================================================================== -->
<!--	TEXT																			-->
<!-- ================================================================================== -->

<xsl:template match="TEXT">
	<xsl:choose>
		<xsl:when test="@R='CONTAINS' and ../@C='CONTINUOUS'">
			<font size="4"><pre><xsl:value-of select="Value"/><xsl:text></xsl:text></pre></font>
		</xsl:when>
		<xsl:otherwise>
			<dl>
			<dt><img src="TEXT.gif" alt="TEXT"/><xsl:text> </xsl:text><xsl:call-template name="ConceptName"/></dt>
			<dd><font size="4"><pre><xsl:value-of select="Value"/> </pre></font></dd>
			</dl>
		</xsl:otherwise>	
	</xsl:choose>

	<xsl:call-template name="ChildNodes"/>
</xsl:template>

<!-- ================================================================================== -->
<!-- CODE																				-->
<!-- ================================================================================== -->

<xsl:template match="CODE">
	<xsl:choose>
		<xsl:when test="@R='CONTAINS' and ../@C='CONTINUOUS'">
			<xsl:value-of select="Value/@CM"/><xsl:text> </xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<dl>
			<dt><img src="CODE.gif" alt="CODE"/><xsl:text> </xsl:text><xsl:call-template name="ConceptName"/></dt>
			<dd>
				<xsl:value-of select="Value/@CM"/>
				<xsl:text> </xsl:text>
				<font size="-1">(<xsl:value-of select="@CV"/>:<xsl:value-of select="@CSD"/>)</font>
			</dd>
			</dl>
		</xsl:otherwise>
	</xsl:choose>

	<xsl:call-template name="ChildNodes"/>
</xsl:template>

<!-- ================================================================================== -->
<!-- NUM																				-->
<!-- ================================================================================== -->

<xsl:template match="NUM">
	<xsl:choose>
		<xsl:when test="@R='CONTAINS' and ../@C='CONTINUOUS'">
			<xsl:value-of select="Value/@CM"/><xsl:text> </xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<dl>
			<dt><img src="NUM.gif" alt="NUM"/><xsl:text> </xsl:text><xsl:call-template name="ConceptName"/></dt>
			<dd><xsl:value-of select="Value"/><xsl:text> </xsl:text><xsl:value-of select="Value/@CM"/></dd>
			</dl>
		</xsl:otherwise>	
	</xsl:choose>

	<xsl:call-template name="ChildNodes"/>
</xsl:template>

<!-- ================================================================================== -->
<!--	DATETIME																		-->
<!-- ================================================================================== -->

<xsl:template match="DATETIME">
	<xsl:choose>
		<xsl:when test="@R='CONTAINS' and ../@C='CONTINUOUS'">
			<xsl:value-of select="Value"/><xsl:text> </xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<dl>
			<dt><img src="DATETIME.gif" alt="DATETIME"/><xsl:text> </xsl:text><xsl:call-template name="ConceptName"/></dt>
			<dd><xsl:value-of select="Value"/></dd>
			</dl>
		</xsl:otherwise>	
	</xsl:choose>

	<xsl:call-template name="ChildNodes"/>
</xsl:template>

<!-- ================================================================================== -->
<!--	DATE																			-->
<!-- ================================================================================== -->

<xsl:template match="DATE">
	<xsl:choose>
		<xsl:when test="@R='CONTAINS' and ../@C='CONTINUOUS'">
			<xsl:value-of select="Value"/><xsl:text> </xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<dl>
			<dt><img src="DATE.gif" alt="DATE"/><xsl:text> </xsl:text><xsl:call-template name="ConceptName"/></dt>
			<dd><xsl:value-of select="Value"/></dd>
			</dl>
		</xsl:otherwise>	
	</xsl:choose>

	<xsl:call-template name="ChildNodes"/>
</xsl:template>

<!-- ================================================================================== -->
<!--	TIME																			-->
<!-- ================================================================================== -->

<xsl:template match="TIME">
	<xsl:choose>
		<xsl:when test="@R='CONTAINS' and ../@C='CONTINUOUS'">
			<xsl:value-of select="Value"/><xsl:text> </xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<dl>
			<dt><img src="TIME.gif" alt="TIME"/><xsl:text> </xsl:text><xsl:call-template name="ConceptName"/></dt>
			<dd><xsl:value-of select="Value"/></dd>
			</dl>
		</xsl:otherwise>	
	</xsl:choose>

	<xsl:call-template name="ChildNodes"/>
</xsl:template>

<!-- ================================================================================== -->
<!--	UIDREF																			-->
<!-- ================================================================================== -->

<xsl:template match="UIDREF">
	<xsl:choose>
		<xsl:when test="@R='CONTAINS' and ../@C='CONTINUOUS'">
			<xsl:value-of select="Value"/><xsl:text> </xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<dl>
			<dt><img src="UIDREF.gif" alt="UIDREF"/><xsl:text> </xsl:text><xsl:call-template name="ConceptName"/></dt>
			<dd><xsl:value-of select="Value"/></dd>
			</dl>
		</xsl:otherwise>	
	</xsl:choose>

	<xsl:call-template name="ChildNodes"/>
</xsl:template>

<!-- ================================================================================== -->
<!--	PNAME																			-->
<!-- ================================================================================== -->

<xsl:template match="PNAME">
	<xsl:choose>
		<xsl:when test="@R='CONTAINS' and ../@C='CONTINUOUS'">
			<xsl:value-of select="Value"/><xsl:text> </xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<dl>
			<dt><img src="PNAME.gif" alt="PNAME"/><xsl:text> </xsl:text><xsl:call-template name="ConceptName"/></dt>
			<dd><xsl:value-of select="Value"/></dd>
			</dl>
		</xsl:otherwise>	
	</xsl:choose>

	<xsl:call-template name="ChildNodes"/>
</xsl:template>

<!-- ================================================================================== -->
<!--	COMPOSITE																		-->
<!-- ================================================================================== -->

<xsl:template match="COMPOSITE">
	<dl>
		<dt><xsl:call-template name="ConceptName"/></dt>
		<xsl:for-each select="Value">
			<dd><img src="COMPOSITE.gif" alt="COMPOSITE"/><xsl:text> </xsl:text><a href="{.}"><xsl:value-of select="@SOPInstanceUID"/></a></dd>
		</xsl:for-each>
	</dl>

	<xsl:call-template name="ChildNodes"/>
</xsl:template>

<!-- ================================================================================== -->
<!--	IMAGE																			-->
<!-- ================================================================================== -->

<xsl:template match="IMAGE">
	<dl>
		<dt><xsl:call-template name="ConceptName"/></dt>
		<xsl:for-each select="Value">
<!-- jtbae 2009.8.11 redmine#2288 -->
<!--			<dd><img src="IMAGE.gif" alt="IMAGE"/><xsl:text> </xsl:text><a href="{.}"><xsl:value-of select="@SOPInstanceUID"/></a></dd>	-->
			<dd><img src="IMAGE.gif" alt="IMAGE"/><xsl:text> </xsl:text><xsl:value-of select="@SOPInstanceUID"/></dd>
		</xsl:for-each>
	</dl>

	<xsl:call-template name="ChildNodes"/>
</xsl:template>

<!-- ================================================================================== -->
<!--	WAVEFORM																		-->
<!-- ================================================================================== -->

<xsl:template match="WAVEFORM">
	<dl>
		<dt><xsl:call-template name="ConceptName"/></dt>
		<xsl:for-each select="Value">
			<dd><img src="WAVEFORM.gif" alt="WAVEFORM"/><xsl:text> </xsl:text><a href="{.}"><xsl:value-of select="@SOPInstanceUID"/></a></dd>
		</xsl:for-each>
	</dl>

	<xsl:call-template name="ChildNodes"/>
</xsl:template>

<!-- ================================================================================== -->
<!--	SCOORD																			-->
<!-- ================================================================================== -->

<xsl:template match="SCOORD">
</xsl:template>

<!-- ================================================================================== -->
<!--	TCOORD																			-->
<!-- ================================================================================== -->

<xsl:template match="TCOORD">
</xsl:template>

<!-- ================================================================================== -->
<!-- ================================================================================== -->

<xsl:template name="ConceptName">
	<xsl:choose>
		<xsl:when test="@CM != '' and @CV != ''">
			<xsl:value-of select="@CM"/>
			<xsl:text> </xsl:text>
			<font size="-1">(<xsl:value-of select="@CV"/>:<xsl:value-of select="@CSD"/>)</font>
		</xsl:when>
		<xsl:when test="@CM = '' and @CV != ''">
			<xsl:value-of select="@CV"/>:<xsl:value-of select="@CSD"/>
		</xsl:when>
		<xsl:otherwise>
			<font size="-1">(Null Section Name)</font>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template name="ChildNodes">
	<xsl:for-each select="TEXT|CODE|NUM|DATETIME|DATE|TIME|UIDREF|PNAME|COMPOSITE|IMAGE|WAVEFORM|SCOORD|TCOORD">
		<dl>
			<dd>
				<xsl:apply-templates select="."/>
			</dd>
		</dl>
	</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
