<?xml version="1.0" encoding="utf-8"?>

<!-- ================================================================================== -->
<!--																					-->
<!--	$Workfile: MFDCMSR.xsl $														-->
<!--	$Author: Switch $																-->
<!--	$Date: 04-10-06 10:21p $														-->
<!--	$Revision: 6 $																	-->
<!--																					-->
<!-- ================================================================================== -->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" omit-xml-declaration="no"/>

	<xsl:template match="DICOM">
		<xsl:element name="SR">
			<xsl:attribute name="schema">1</xsl:attribute>
			<xsl:call-template name="ReadGeneralAttributes"/>
			<xsl:call-template name="CONTAINER"/>
		</xsl:element>
	</xsl:template>

	<xsl:template match="SR">
		<xsl:element name="DICOM">
			<xsl:call-template name="WriteGeneralAttributes"/>
			<xsl:apply-templates/>
		</xsl:element>
	</xsl:template>

	<xsl:template match="Value">
		<xsl:call-template name="TEXT"/>
		<xsl:call-template name="CODE"/>
		<xsl:call-template name="NUM"/>
		<xsl:call-template name="DATETIME"/>
		<xsl:call-template name="DATE"/>
		<xsl:call-template name="TIME"/>
		<xsl:call-template name="PNAME"/>
		<xsl:call-template name="UIDREF"/>
		<xsl:call-template name="COMPOSITE"/>
		<xsl:call-template name="IMAGE"/>
		<xsl:call-template name="WAVEFORM"/>
		<xsl:call-template name="SCOORD"/>
		<xsl:call-template name="TCOORD"/>
		<xsl:call-template name="CONTAINER"/>
	</xsl:template>

<!-- ================================================================================== -->
<!--	General Attributes																-->
<!-- ================================================================================== -->

	<xsl:template name="ReadGeneralAttributes">
		<xsl:element name="Patient">
			<xsl:attribute name="N">
				<xsl:value-of select="Element[@tag='#x00100010']/Value"/>
			</xsl:attribute>
			<xsl:attribute name="I">
				<xsl:value-of select="Element[@tag='#x00100020']/Value"/>
			</xsl:attribute>
			<xsl:attribute name="D">
				<xsl:value-of select="Element[@tag='#x00100030']/Value"/>
			</xsl:attribute>
			<xsl:attribute name="S">
				<xsl:value-of select="Element[@tag='#x00100040']/Value"/>
			</xsl:attribute>
		</xsl:element>

		<xsl:element name="Study">
			<xsl:attribute name="U">
				<xsl:value-of select="Element[@tag='#x0020000D']/Value"/>
			</xsl:attribute>
			<xsl:attribute name="I">
				<xsl:value-of select="Element[@tag='#x00200010']/Value"/>
			</xsl:attribute>
			<xsl:attribute name="A">
				<xsl:value-of select="Element[@tag='#x00080050']/Value"/>
			</xsl:attribute>
			<xsl:attribute name="D">
				<xsl:value-of select="Element[@tag='#x00080020']/Value"/>
			</xsl:attribute>
			<xsl:attribute name="T">
				<xsl:value-of select="Element[@tag='#x00080030']/Value"/>
			</xsl:attribute>
		</xsl:element>

		<xsl:element name="Series">
			<xsl:attribute name="U">
				<xsl:value-of select="Element[@tag='#x0020000E']/Value"/>
			</xsl:attribute>
			<xsl:attribute name="M">
				<xsl:value-of select="Element[@tag='#x00080060']/Value"/>
			</xsl:attribute>
		</xsl:element>

		<xsl:element name="Instance">
			<xsl:attribute name="C">
				<xsl:value-of select="Element[@tag='#x00080016']/Value"/>
			</xsl:attribute>
			<xsl:attribute name="U">
				<xsl:value-of select="Element[@tag='#x00080018']/Value"/>
			</xsl:attribute>
			<xsl:attribute name="D">
				<xsl:value-of select="Element[@tag='#x00080023']/Value"/>
			</xsl:attribute>
			<xsl:attribute name="T">
				<xsl:value-of select="Element[@tag='#x00080033']/Value"/>
			</xsl:attribute>
		</xsl:element>

		<xsl:element name="Verifier">
			<xsl:attribute name="O">
				<xsl:value-of select="Element[@tag='#x0040A073']/Value/Element[@tag='#x0040A027']/Value"/>
			</xsl:attribute>
			<xsl:attribute name="D">
				<xsl:value-of select="Element[@tag='#x0040A073']/Value/Element[@tag='#x0040A030']/Value"/>
			</xsl:attribute>
			<xsl:attribute name="N">
				<xsl:value-of select="Element[@tag='#x0040A073']/Value/Element[@tag='#x0040A075']/Value"/>
			</xsl:attribute>
			<xsl:for-each select="Element[@tag='#x0040A073']/Value/Element[@tag='#x0040A088']/Value">
				<xsl:call-template name="ReadCode"/>
			</xsl:for-each>
		</xsl:element>

		<xsl:element name="Status">
			<xsl:attribute name="C">
				<xsl:choose>
					<xsl:when test="Element[@tag='#x0040A491']/Value = 'COMPLETE'">COMPLETE</xsl:when>
					<xsl:otherwise>PARTIAL</xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
			<xsl:attribute name="V">
				<xsl:choose>
					<xsl:when test="Element[@tag='#x0040A493']/Value = 'VERIFIED'">VERIFIED</xsl:when>
					<xsl:otherwise>UNVERIFIED</xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
		</xsl:element>

		<xsl:element name="Template">
			<xsl:attribute name="R">
				<xsl:value-of select="Element[@tag='#x0040A504']/Value/Element[@tag='#x00080105']/Value"/>
			</xsl:attribute>
			<xsl:attribute name="I">
				<xsl:value-of select="Element[@tag='#x0040A504']/Value/Element[@tag='#x0040DB00']/Value"/>
			</xsl:attribute>
		</xsl:element>
	</xsl:template>

	<xsl:template name="WriteGeneralAttributes">
		<xsl:element name="Element">
			<xsl:attribute name="tag">#x00100010</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Patient/@N"/></xsl:element>
		</xsl:element>
		<xsl:element name="Element">
			<xsl:attribute name="tag">#x00100020</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Patient/@I"/></xsl:element>
		</xsl:element>
		<xsl:element name="Element">
			<xsl:attribute name="tag">#x00100030</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Patient/@D"/></xsl:element>
		</xsl:element>
		<xsl:element name="Element">
			<xsl:attribute name="tag">#x00100040</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Patient/@S"/></xsl:element>
		</xsl:element>

		<xsl:element name="Element">
			<xsl:attribute name="tag">#x0020000D</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Study/@U"/></xsl:element>
		</xsl:element>
		<xsl:element name="Element">
			<xsl:attribute name="tag">#x00200010</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Study/@I"/></xsl:element>
		</xsl:element>
		<xsl:element name="Element">
			<xsl:attribute name="tag">#x00080050</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Study/@A"/></xsl:element>
		</xsl:element>
		<xsl:element name="Element">
			<xsl:attribute name="tag">#x00080020</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Study/@D"/></xsl:element>
		</xsl:element>
		<xsl:element name="Element">
			<xsl:attribute name="tag">#x00080030</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Study/@T"/></xsl:element>
		</xsl:element>

		<xsl:element name="Element">
			<xsl:attribute name="tag">#x0020000E</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Series/@U"/></xsl:element>
		</xsl:element>
		<xsl:element name="Element">
			<xsl:attribute name="tag">#x00080060</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Series/@M"/></xsl:element>
		</xsl:element>

		<xsl:element name="Element">
			<xsl:attribute name="tag">#x00080016</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Instance/@C"/></xsl:element>
		</xsl:element>
		<xsl:element name="Element">
			<xsl:attribute name="tag">#x00080018</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Instance/@U"/></xsl:element>
		</xsl:element>
		<xsl:element name="Element">
			<xsl:attribute name="tag">#x00080023</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Instance/@D"/></xsl:element>
		</xsl:element>
		<xsl:element name="Element">
			<xsl:attribute name="tag">#x00080033</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Instance/@T"/></xsl:element>
		</xsl:element>

		<xsl:if test="Status/@V = 'VERIFIED'">
			<xsl:element name="Element">
				<xsl:attribute name="tag">#x0040A073</xsl:attribute>
				<xsl:attribute name="VR">SQ</xsl:attribute>
				<xsl:element name="Value">
					<xsl:element name="Element">
						<xsl:attribute name="tag">#x0040A027</xsl:attribute>
						<xsl:attribute name="VR">.</xsl:attribute>
						<xsl:element name="Value"><xsl:value-of select="Verifier/@O"/></xsl:element>
					</xsl:element>
					<xsl:element name="Element">
						<xsl:attribute name="tag">#x0040A030</xsl:attribute>
						<xsl:attribute name="VR">.</xsl:attribute>
						<xsl:element name="Value"><xsl:value-of select="Verifier/@D"/></xsl:element>
					</xsl:element>
					<xsl:element name="Element">
						<xsl:attribute name="tag">#x0040A075</xsl:attribute>
						<xsl:attribute name="VR">.</xsl:attribute>
						<xsl:element name="Value"><xsl:value-of select="Verifier/@N"/></xsl:element>
					</xsl:element>
					<xsl:element name="Element">
						<xsl:attribute name="tag">#x0040A088</xsl:attribute>
						<xsl:attribute name="VR">SQ</xsl:attribute>
						<xsl:for-each select="Verifier">
							<xsl:call-template name="WriteCode"/>
						</xsl:for-each>
					</xsl:element>
				</xsl:element>
			</xsl:element>
		</xsl:if>

		<xsl:element name="Element">
			<xsl:attribute name="tag">#x0040A491</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Status/@C"/></xsl:element>
		</xsl:element>
		<xsl:element name="Element">
			<xsl:attribute name="tag">#x0040A493</xsl:attribute>
			<xsl:attribute name="VR">.</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="Status/@V"/></xsl:element>
		</xsl:element>

		<xsl:element name="Element">
			<xsl:attribute name="tag">#x0040A504</xsl:attribute>
			<xsl:attribute name="VR">SQ</xsl:attribute>
			<xsl:element name="Value">
				<xsl:element name="Element">
					<xsl:attribute name="tag">#x00080105</xsl:attribute>
					<xsl:attribute name="VR">.</xsl:attribute>
					<xsl:element name="Value"><xsl:value-of select="Template/@R"/></xsl:element>
				</xsl:element>
				<xsl:element name="Element">
					<xsl:attribute name="tag">#x0040DB00</xsl:attribute>
					<xsl:attribute name="VR">.</xsl:attribute>
					<xsl:element name="Value"><xsl:value-of select="Template/@I"/></xsl:element>
				</xsl:element>
			</xsl:element>
		</xsl:element>
	</xsl:template>

<!-- ================================================================================== -->
<!--	CONTAINER																		-->
<!-- ================================================================================== -->

	<xsl:template name="CONTAINER">
		<xsl:if test="Element[@tag='#x0040A040']/Value='CONTAINER'">
			<xsl:element name="CONTAINER">
				<xsl:call-template name="ReadRelationship"/>
				<xsl:call-template name="ReadContinuity"/>
				<xsl:call-template name="ReadConceptName"/>

				<xsl:call-template name="ReadChildNodes"/>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<xsl:template match="CONTAINER">
		<xsl:call-template name="WriteRelationship"/>
		<xsl:call-template name="WriteValueType"/>
		<xsl:call-template name="WriteConceptName"/>
		<xsl:call-template name="WriteContinuity"/>

		<xsl:call-template name="WriteChildNodes"/>
	</xsl:template>

<!-- ================================================================================== -->
<!--	TEXT																			-->
<!-- ================================================================================== -->

	<xsl:template name="TEXT">
		<xsl:if test="Element[@tag='#x0040A040']/Value='TEXT'">
			<xsl:element name="TEXT">
				<xsl:call-template name="ReadRelationship"/>
				<xsl:call-template name="ReadConceptName"/>

				<xsl:element name="Value">
					<xsl:value-of select="Element[@tag='#x0040A160']/Value"/>
				</xsl:element>

				<xsl:call-template name="ReadChildNodes"/>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<xsl:template match="TEXT">
		<xsl:call-template name="WriteRelationship"/>
		<xsl:call-template name="WriteValueType"/>
		<xsl:call-template name="WriteConceptName"/>

		<xsl:element name="Element">
			<xsl:attribute name="tag">#x0040A160</xsl:attribute>
			<xsl:attribute name="VR">UT</xsl:attribute>
			<xsl:attribute name="name">Text Value</xsl:attribute>
			<xsl:for-each select="Value">
				<xsl:element name="Value"><xsl:value-of select="."/></xsl:element>
			</xsl:for-each>
		</xsl:element>

		<xsl:call-template name="WriteChildNodes">
			<xsl:with-param name="self" select="'Value'"/>
		</xsl:call-template>
	</xsl:template>

<!-- ================================================================================== -->
<!--	CODE																			-->
<!-- ================================================================================== -->

	<xsl:template name="CODE">
		<xsl:if test="Element[@tag='#x0040A040']/Value='CODE'">
			<xsl:element name="CODE">
				<xsl:call-template name="ReadRelationship"/>
				<xsl:call-template name="ReadConceptName"/>

				<xsl:for-each select="./Element[@tag='#x0040A168']/Value">
					<xsl:element name="Value">
						<xsl:call-template name="ReadCode"/>
					</xsl:element>
				</xsl:for-each>

				<xsl:call-template name="ReadChildNodes"/>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<xsl:template match="CODE">
		<xsl:call-template name="WriteRelationship"/>
		<xsl:call-template name="WriteValueType"/>
		<xsl:call-template name="WriteConceptName"/>

		<xsl:element name="Element">
			<xsl:attribute name="tag">#x0040A168</xsl:attribute>
			<xsl:attribute name="VR">SQ</xsl:attribute>
			<xsl:attribute name="name">Code Sequence</xsl:attribute>
			<xsl:for-each select="Value">
				<xsl:call-template name="WriteCode"/>
			</xsl:for-each>
		</xsl:element>

		<xsl:call-template name="WriteChildNodes">
			<xsl:with-param name="self" select="'Value'"/>
		</xsl:call-template>
	</xsl:template>

<!-- ================================================================================== -->
<!--	NUM																				-->
<!-- ================================================================================== -->

	<xsl:template name="NUM">
		<xsl:if test="Element[@tag='#x0040A040']/Value='NUM'">
			<xsl:element name="NUM">
				<xsl:call-template name="ReadRelationship"/>
				<xsl:call-template name="ReadConceptName"/>

				<xsl:for-each select="Element[@tag='#x0040A300']/Value">
					<xsl:element name="Value">
						<xsl:for-each select="Element[@tag='#x004008EA']/Value">
							<xsl:call-template name="ReadCode"/>
						</xsl:for-each>
						<xsl:value-of select="Element[@tag='#x0040A30A']/Value"/>
					</xsl:element>
				</xsl:for-each>

				<xsl:call-template name="ReadChildNodes"/>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<xsl:template match="NUM">
		<xsl:call-template name="WriteRelationship"/>
		<xsl:call-template name="WriteValueType"/>
		<xsl:call-template name="WriteConceptName"/>

		<xsl:element name="Element">
			<xsl:attribute name="tag">#x0040A300</xsl:attribute>
			<xsl:attribute name="VR">SQ</xsl:attribute>
			<xsl:attribute name="name">Measured Value Sequence</xsl:attribute>
			<xsl:for-each select="Value">
				<xsl:element name="Value">
					<xsl:element name="Element">
						<xsl:attribute name="tag">#x004008EA</xsl:attribute>
						<xsl:attribute name="VR">SQ</xsl:attribute>
						<xsl:attribute name="name">Measurement Unit Code Sequence</xsl:attribute>
						<xsl:call-template name="WriteCode"/>
					</xsl:element>
					<xsl:element name="Element">
						<xsl:attribute name="tag">#x0040A30A</xsl:attribute>
						<xsl:attribute name="VR">DS</xsl:attribute>
						<xsl:attribute name="name">Numeric Value</xsl:attribute>
						<xsl:element name="Value">
							<xsl:value-of select="."/>
						</xsl:element>
					</xsl:element>
				</xsl:element>
			</xsl:for-each>
		</xsl:element>

		<xsl:call-template name="WriteChildNodes">
			<xsl:with-param name="self" select="'Value'"/>
		</xsl:call-template>
	</xsl:template>

<!-- ================================================================================== -->
<!--	DATETIME																		-->
<!-- ================================================================================== -->

	<xsl:template name="DATETIME">
		<xsl:if test="Element[@tag='#x0040A040']/Value='DATETIME'">
			<xsl:element name="DATETIME">
				<xsl:call-template name="ReadRelationship"/>
				<xsl:call-template name="ReadConceptName"/>

				<xsl:element name="Value">
					<xsl:value-of select="Element[@tag='#x0040A120']/Value"/>
				</xsl:element>

				<xsl:call-template name="ReadChildNodes"/>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<xsl:template match="DATETIME">
		<xsl:call-template name="WriteRelationship"/>
		<xsl:call-template name="WriteValueType"/>
		<xsl:call-template name="WriteConceptName"/>

		<xsl:element name="Element">
			<xsl:attribute name="tag">#x0040A120</xsl:attribute>
			<xsl:attribute name="VR">DT</xsl:attribute>
			<xsl:attribute name="name">DateTime</xsl:attribute>
			<xsl:for-each select="Value">
				<xsl:element name="Value"><xsl:value-of select="."/></xsl:element>
			</xsl:for-each>
		</xsl:element>

		<xsl:call-template name="WriteChildNodes">
			<xsl:with-param name="self" select="'Value'"/>
		</xsl:call-template>
	</xsl:template>

<!-- ================================================================================== -->
<!--	DATE																			-->
<!-- ================================================================================== -->

	<xsl:template name="DATE">
		<xsl:if test="Element[@tag='#x0040A040']/Value='DATE'">
			<xsl:element name="DATE">
				<xsl:call-template name="ReadRelationship"/>
				<xsl:call-template name="ReadConceptName"/>

				<xsl:element name="Value">
					<xsl:value-of select="Element[@tag='#x0040A121']/Value"/>
				</xsl:element>

				<xsl:call-template name="ReadChildNodes"/>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<xsl:template match="DATE">
		<xsl:call-template name="WriteRelationship"/>
		<xsl:call-template name="WriteValueType"/>
		<xsl:call-template name="WriteConceptName"/>

		<xsl:element name="Element">
			<xsl:attribute name="tag">#x0040A121</xsl:attribute>
			<xsl:attribute name="VR">DA</xsl:attribute>
			<xsl:attribute name="name">Date</xsl:attribute>
			<xsl:for-each select="Value">
				<xsl:element name="Value"><xsl:value-of select="."/></xsl:element>
			</xsl:for-each>
		</xsl:element>

		<xsl:call-template name="WriteChildNodes">
			<xsl:with-param name="self" select="'Value'"/>
		</xsl:call-template>
	</xsl:template>

<!-- ================================================================================== -->
<!--	TIME																			-->
<!-- ================================================================================== -->

	<xsl:template name="TIME">
		<xsl:if test="Element[@tag='#x0040A040']/Value='TIME'">
			<xsl:element name="TIME">
				<xsl:call-template name="ReadRelationship"/>
				<xsl:call-template name="ReadConceptName"/>

				<xsl:element name="Value">
					<xsl:value-of select="Element[@tag='#x0040A122']/Value"/>
				</xsl:element>

				<xsl:call-template name="ReadChildNodes"/>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<xsl:template match="TIME">
		<xsl:call-template name="WriteRelationship"/>
		<xsl:call-template name="WriteValueType"/>
		<xsl:call-template name="WriteConceptName"/>

		<xsl:element name="Element">
			<xsl:attribute name="tag">#x0040A122</xsl:attribute>
			<xsl:attribute name="VR">TM</xsl:attribute>
			<xsl:attribute name="name">Time</xsl:attribute>
			<xsl:for-each select="Value">
				<xsl:element name="Value"><xsl:value-of select="."/></xsl:element>
			</xsl:for-each>
		</xsl:element>

		<xsl:call-template name="WriteChildNodes">
			<xsl:with-param name="self" select="'Value'"/>
		</xsl:call-template>
	</xsl:template>

<!-- ================================================================================== -->
<!--	PNAME																			-->
<!-- ================================================================================== -->

	<xsl:template name="PNAME">
		<xsl:if test="Element[@tag='#x0040A040']/Value='PNAME'">
			<xsl:element name="PNAME">
				<xsl:call-template name="ReadRelationship"/>
				<xsl:call-template name="ReadConceptName"/>

				<xsl:element name="Value">
					<xsl:value-of select="Element[@tag='#x0040A123']/Value"/>
				</xsl:element>

				<xsl:call-template name="ReadChildNodes"/>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<xsl:template match="PNAME">
		<xsl:call-template name="WriteRelationship"/>
		<xsl:call-template name="WriteValueType"/>
		<xsl:call-template name="WriteConceptName"/>

		<xsl:element name="Element">
			<xsl:attribute name="tag">#x0040A123</xsl:attribute>
			<xsl:attribute name="VR">PN</xsl:attribute>
			<xsl:attribute name="name">Person Name</xsl:attribute>
			<xsl:for-each select="Value">
				<xsl:element name="Value"><xsl:value-of select="."/></xsl:element>
			</xsl:for-each>
		</xsl:element>

		<xsl:call-template name="WriteChildNodes">
			<xsl:with-param name="self" select="'Value'"/>
		</xsl:call-template>
	</xsl:template>

<!-- ================================================================================== -->
<!--	UIDREF																			-->
<!-- ================================================================================== -->

	<xsl:template name="UIDREF">
		<xsl:if test="Element[@tag='#x0040A040']/Value='UIDREF'">
			<xsl:element name="UIDREF">
				<xsl:call-template name="ReadRelationship"/>
				<xsl:call-template name="ReadConceptName"/>

				<xsl:element name="Value">
					<xsl:value-of select="Element[@tag='#x0040A124']/Value"/>
				</xsl:element>

				<xsl:call-template name="ReadChildNodes"/>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<xsl:template match="UIDREF">
		<xsl:call-template name="WriteRelationship"/>
		<xsl:call-template name="WriteValueType"/>
		<xsl:call-template name="WriteConceptName"/>

		<xsl:element name="Element">
			<xsl:attribute name="tag">#x0040A124</xsl:attribute>
			<xsl:attribute name="VR">UI</xsl:attribute>
			<xsl:attribute name="name">UID</xsl:attribute>
			<xsl:for-each select="Value">
				<xsl:element name="Value"><xsl:value-of select="."/></xsl:element>
			</xsl:for-each>
		</xsl:element>

		<xsl:call-template name="WriteChildNodes">
			<xsl:with-param name="self" select="'Value'"/>
		</xsl:call-template>
	</xsl:template>

<!-- ================================================================================== -->
<!--	COMPOSITE																		-->
<!-- ================================================================================== -->

	<xsl:template name="COMPOSITE">
		<xsl:if test="Element[@tag='#x0040A040']/Value='COMPOSITE'">
			<xsl:element name="COMPOSITE">
				<xsl:call-template name="ReadRelationship"/>
				<xsl:call-template name="ReadConceptName"/>

				<xsl:for-each select="./Element[@tag='#x00081199']/Value">
					<xsl:element name="Value">
						<xsl:attribute name="SOPClassUID">
							<xsl:value-of select="Element[@tag='#x00081150']/Value"/>
						</xsl:attribute>
						<xsl:attribute name="SOPInstanceUID">
							<xsl:value-of select="Element[@tag='#x00081155']/Value"/>
						</xsl:attribute>
					</xsl:element>
				</xsl:for-each>

				<xsl:call-template name="ReadChildNodes"/>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<xsl:template match="COMPOSITE">
		<xsl:call-template name="WriteRelationship"/>
		<xsl:call-template name="WriteValueType"/>
		<xsl:call-template name="WriteConceptName"/>

		<xsl:element name="Element">
			<xsl:attribute name="tag">#x00081199</xsl:attribute>
			<xsl:attribute name="VR">SQ</xsl:attribute>
			<xsl:attribute name="name">Referenced SOP Sequence</xsl:attribute>
			<xsl:for-each select="Value">
				<xsl:element name="Value">
					<xsl:element name="Element">
						<xsl:attribute name="tag">#x00081150</xsl:attribute>
						<xsl:attribute name="VR">UI</xsl:attribute>
						<xsl:attribute name="name">Referenced SOP Class UID</xsl:attribute>
						<xsl:element name="Value">
							<xsl:value-of select="@SOPClassUID"/>
						</xsl:element>
					</xsl:element>
					<xsl:element name="Element">
						<xsl:attribute name="tag">#x00081155</xsl:attribute>
						<xsl:attribute name="VR">UI</xsl:attribute>
						<xsl:attribute name="name">Referenced SOP Instance UID</xsl:attribute>
						<xsl:element name="Value">
							<xsl:value-of select="@SOPInstanceUID"/>
						</xsl:element>
					</xsl:element>
				</xsl:element>
			</xsl:for-each>
		</xsl:element>

		<xsl:call-template name="WriteChildNodes">
			<xsl:with-param name="self" select="'Value'"/>
		</xsl:call-template>
	</xsl:template>

<!-- ================================================================================== -->
<!--	IMAGE (not yet fully implemented)												-->
<!-- ================================================================================== -->

	<xsl:template name="IMAGE">
		<xsl:if test="Element[@tag='#x0040A040']/Value='IMAGE'">
			<xsl:element name="IMAGE">
				<xsl:call-template name="ReadRelationship"/>
				<xsl:call-template name="ReadConceptName"/>

				<xsl:for-each select="./Element[@tag='#x00081199']/Value">
					<xsl:element name="Value">
						<xsl:attribute name="SOPClassUID">
							<xsl:value-of select="Element[@tag='#x00081150']/Value"/>
						</xsl:attribute>
						<xsl:attribute name="SOPInstanceUID">
							<xsl:value-of select="Element[@tag='#x00081155']/Value"/>
						</xsl:attribute>
					</xsl:element>
				</xsl:for-each>

				<xsl:call-template name="ReadChildNodes"/>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<xsl:template match="IMAGE">
		<xsl:call-template name="WriteRelationship"/>
		<xsl:call-template name="WriteValueType"/>
		<xsl:call-template name="WriteConceptName"/>

		<xsl:element name="Element">
			<xsl:attribute name="tag">#x00081199</xsl:attribute>
			<xsl:attribute name="VR">SQ</xsl:attribute>
			<xsl:attribute name="name">Referenced SOP Sequence</xsl:attribute>
			<xsl:for-each select="Value">
				<xsl:element name="Value">
					<xsl:element name="Element">
						<xsl:attribute name="tag">#x00081150</xsl:attribute>
						<xsl:attribute name="VR">UI</xsl:attribute>
						<xsl:attribute name="name">Referenced SOP Class UID</xsl:attribute>
						<xsl:element name="Value">
							<xsl:value-of select="@SOPClassUID"/>
						</xsl:element>
					</xsl:element>
					<xsl:element name="Element">
						<xsl:attribute name="tag">#x00081155</xsl:attribute>
						<xsl:attribute name="VR">UI</xsl:attribute>
						<xsl:attribute name="name">Referenced SOP Instance UID</xsl:attribute>
						<xsl:element name="Value">
							<xsl:value-of select="@SOPInstanceUID"/>
						</xsl:element>
					</xsl:element>
				</xsl:element>
			</xsl:for-each>
		</xsl:element>

		<xsl:call-template name="WriteChildNodes">
			<xsl:with-param name="self" select="'Value'"/>
		</xsl:call-template>
	</xsl:template>

<!-- ================================================================================== -->
<!--	WAVEFORM (not yet fully implemented)											-->
<!-- ================================================================================== -->

	<xsl:template name="WAVEFORM">
		<xsl:if test="Element[@tag='#x0040A040']/Value='WAVEFORM'">
			<xsl:element name="WAVEFORM">
				<xsl:call-template name="ReadRelationship"/>
				<xsl:call-template name="ReadConceptName"/>

				<xsl:for-each select="./Element[@tag='#x00081199']/Value">
					<xsl:element name="Value">
						<xsl:attribute name="SOPClassUID">
							<xsl:value-of select="Element[@tag='#x00081150']/Value"/>
						</xsl:attribute>
						<xsl:attribute name="SOPInstanceUID">
							<xsl:value-of select="Element[@tag='#x00081155']/Value"/>
						</xsl:attribute>
					</xsl:element>
				</xsl:for-each>

				<xsl:call-template name="ReadChildNodes"/>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<xsl:template match="WAVEFORM">
		<xsl:call-template name="WriteRelationship"/>
		<xsl:call-template name="WriteValueType"/>
		<xsl:call-template name="WriteConceptName"/>

		<xsl:element name="Element">
			<xsl:attribute name="tag">#x00081199</xsl:attribute>
			<xsl:attribute name="VR">SQ</xsl:attribute>
			<xsl:attribute name="name">Referenced SOP Sequence</xsl:attribute>
			<xsl:for-each select="Value">
				<xsl:element name="Value">
					<xsl:element name="Element">
						<xsl:attribute name="tag">#x00081150</xsl:attribute>
						<xsl:attribute name="VR">UI</xsl:attribute>
						<xsl:attribute name="name">Referenced SOP Class UID</xsl:attribute>
						<xsl:element name="Value">
							<xsl:value-of select="@SOPClassUID"/>
						</xsl:element>
					</xsl:element>
					<xsl:element name="Element">
						<xsl:attribute name="tag">#x00081155</xsl:attribute>
						<xsl:attribute name="VR">UI</xsl:attribute>
						<xsl:attribute name="name">Referenced SOP Instance UID</xsl:attribute>
						<xsl:element name="Value">
							<xsl:value-of select="@SOPInstanceUID"/>
						</xsl:element>
					</xsl:element>
				</xsl:element>
			</xsl:for-each>
		</xsl:element>

		<xsl:call-template name="WriteChildNodes">
			<xsl:with-param name="self" select="'Value'"/>
		</xsl:call-template>
	</xsl:template>

<!-- ================================================================================== -->
<!--	SCOORD (not yet fully implemented)												-->
<!-- ================================================================================== -->

	<xsl:template name="SCOORD">
		<xsl:if test="Element[@tag='#x0040A040']/Value='SCOORD'">
			<xsl:element name="SCOORD">
				<xsl:call-template name="ReadRelationship"/>
				<xsl:call-template name="ReadConceptName"/>

				<xsl:call-template name="ReadChildNodes"/>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<xsl:template match="SCOORD">
		<xsl:call-template name="WriteRelationship"/>
		<xsl:call-template name="WriteValueType"/>
		<xsl:call-template name="WriteConceptName"/>

		<xsl:call-template name="WriteChildNodes">
			<xsl:with-param name="self" select="'Value'"/>
		</xsl:call-template>
	</xsl:template>

<!-- ================================================================================== -->
<!--	TCOORD (not yet fully implemented)												-->
<!-- ================================================================================== -->

	<xsl:template name="TCOORD">
		<xsl:if test="Element[@tag='#x0040A040']/Value='TCOORD'">
			<xsl:element name="TCOORD">
				<xsl:call-template name="ReadRelationship"/>
				<xsl:call-template name="ReadConceptName"/>

				<xsl:call-template name="ReadChildNodes"/>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<xsl:template match="TCOORD">
		<xsl:call-template name="WriteRelationship"/>
		<xsl:call-template name="WriteValueType"/>
		<xsl:call-template name="WriteConceptName"/>

		<xsl:call-template name="WriteChildNodes">
			<xsl:with-param name="self" select="'Value'"/>
		</xsl:call-template>
	</xsl:template>

<!-- ================================================================================== -->
<!--	Relationship																	-->
<!-- ================================================================================== -->

	<xsl:template name="ReadRelationship">
		<xsl:if test="count(Element[@tag='#x0040A010']/Value) > 0">
			<xsl:attribute name="R">
				<xsl:value-of select="Element[@tag='#x0040A010']/Value"/>
			</xsl:attribute>
		</xsl:if>
	</xsl:template>

	<xsl:template name="WriteRelationship">
		<xsl:if test="@R != ''">
			<xsl:element name="Element">
				<xsl:attribute name="tag">#x0040A010</xsl:attribute>
				<xsl:attribute name="VR">CS</xsl:attribute>
				<xsl:attribute name="name">Relationship Type</xsl:attribute>
				<xsl:element name="Value"><xsl:value-of select="@R"/></xsl:element>		
			</xsl:element>
		</xsl:if>
	</xsl:template>

<!-- ================================================================================== -->
<!--	Value Type																		-->
<!-- ================================================================================== -->

	<xsl:template name="WriteValueType">
		<xsl:element name="Element">
			<xsl:attribute name="tag">#x0040A040</xsl:attribute>
			<xsl:attribute name="VR">CS</xsl:attribute>
			<xsl:attribute name="name">Value Type</xsl:attribute>
			<xsl:element name="Value"><xsl:value-of select="name()"/></xsl:element>
		</xsl:element>
	</xsl:template>

<!-- ================================================================================== -->
<!--	Continuity																		-->
<!-- ================================================================================== -->

	<xsl:template name="ReadContinuity">
		<xsl:if test="count(Element[@tag='#x0040A050']/Value) > 0">
			<xsl:attribute name="C">
				<xsl:value-of select="Element[@tag='#x0040A050']/Value"/>
			</xsl:attribute>
		</xsl:if>
	</xsl:template>

	<xsl:template name="WriteContinuity">
		<xsl:if test="@C != ''">
			<xsl:element name="Element">
				<xsl:attribute name="tag">#x0040A050</xsl:attribute>
				<xsl:attribute name="VR">CS</xsl:attribute>
				<xsl:attribute name="name">Continuity of Content</xsl:attribute>
				<xsl:element name="Value"><xsl:value-of select="@C"/></xsl:element>
			</xsl:element>
		</xsl:if>
	</xsl:template>

<!-- ================================================================================== -->
<!--	Concept Name																	-->
<!-- ================================================================================== -->

	<xsl:template name="ReadConceptName">
		<xsl:for-each select="./Element[@tag='#x0040A043']/Value">
			<xsl:call-template name="ReadCode"/>
		</xsl:for-each>
	</xsl:template>

	<xsl:template name="WriteConceptName">
		<xsl:element name="Element">
			<xsl:attribute name="tag">#x0040A043</xsl:attribute>
			<xsl:attribute name="VR">SQ</xsl:attribute>
			<xsl:attribute name="name">Concept-name Code Sequence</xsl:attribute>
			<xsl:call-template name="WriteCode"/>
		</xsl:element>
	</xsl:template>

<!-- ================================================================================== -->
<!--	Code																			-->
<!-- ================================================================================== -->

	<xsl:template name="ReadCode">
		<xsl:attribute name="CV">
			<xsl:value-of select="Element[@tag='#x00080100']/Value"/>
		</xsl:attribute>
		<xsl:attribute name="CSD">
			<xsl:value-of select="Element[@tag='#x00080102']/Value"/>
		</xsl:attribute>
		<xsl:if test="count(Element[@tag='#x00080103']/Value) > 0">
			<xsl:attribute name="CSV">
				<xsl:value-of select="Element[@tag='#x00080103']/Value"/>
			</xsl:attribute>
		</xsl:if>
		<xsl:if test="count(Element[@tag='#x00080104']/Value) > 0">
			<xsl:attribute name="CM">
				<xsl:value-of select="Element[@tag='#x00080104']/Value"/>
			</xsl:attribute>
		</xsl:if>
	</xsl:template>

	<xsl:template name="WriteCode">
		<xsl:element name="Value">
			<xsl:element name="Element">
				<xsl:attribute name="tag">#x00080100</xsl:attribute>
				<xsl:attribute name="VR">SH</xsl:attribute>
				<xsl:attribute name="name">Code Value</xsl:attribute>
				<xsl:element name="Value"><xsl:value-of select="@CV"/></xsl:element>
			</xsl:element>
			<xsl:element name="Element">
				<xsl:attribute name="tag">#x00080102</xsl:attribute>
				<xsl:attribute name="VR">SH</xsl:attribute>
				<xsl:attribute name="name">Coding Scheme Designator</xsl:attribute>
				<xsl:element name="Value"><xsl:value-of select="@CSD"/></xsl:element>
			</xsl:element>
			<xsl:if test="@CSV != ''">
				<xsl:element name="Element">
					<xsl:attribute name="tag">#x00080103</xsl:attribute>
					<xsl:attribute name="VR">LO</xsl:attribute>
					<xsl:attribute name="name">Code Meaning</xsl:attribute>
					<xsl:element name="Value"><xsl:value-of select="@CSV"/></xsl:element>
				</xsl:element>
			</xsl:if>
			<xsl:if test="@CM != ''">
				<xsl:element name="Element">
					<xsl:attribute name="tag">#x00080104</xsl:attribute>
					<xsl:attribute name="VR">LO</xsl:attribute>
					<xsl:attribute name="name">Code Meaning</xsl:attribute>
					<xsl:element name="Value"><xsl:value-of select="@CM"/></xsl:element>
				</xsl:element>
			</xsl:if>
		</xsl:element>
	</xsl:template>

<!-- ================================================================================== -->
<!--	Child Nodes																		-->
<!-- ================================================================================== -->

	<xsl:template name="ReadChildNodes">
		<xsl:apply-templates select="Element[@tag='#x0040A730']/Value"/>
	</xsl:template>

	<xsl:template name="WriteChildNodes">
		<xsl:param name="self" select="''"/>
		<xsl:if test="count(*[name() != $self]) > 0">
			<xsl:element name="Element">
				<xsl:attribute name="tag">#x0040A730</xsl:attribute>
				<xsl:attribute name="VR">SQ</xsl:attribute>
				<xsl:attribute name="name">Content Sequence</xsl:attribute>
				<xsl:for-each select="*[name() != $self]">
					<xsl:element name="Value">
						<xsl:apply-templates select="."/>
					</xsl:element>
				</xsl:for-each>
			</xsl:element>
		</xsl:if>
	</xsl:template>

</xsl:stylesheet>
