<?xml version="1.0" encoding="UTF-8"?>
<!--Raymond Yee (yee@uclink.berkeley.edu) , Interactive University, University of California, Berkeley 2002-02-25 -->
<!--&nbsp; trick from http://www.mycgiserver.com/~~lisali/papers/paper.htm -->
<!DOCTYPE stylesheet [
	<!ENTITY nbsp "<xsl:text disable-output-escaping=&#34;yes&#34; 
    xmlns:xsl= &#34;http://www.w3.org/1999/XSL/Transform &#34;
    >&amp;nbsp;</xsl:text>">
]>
<xsl:stylesheet version="1.0"  xmlns="http://www.imsglobal.org/xsd/imscp_v1p1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<!--
</xsl:stylesheet> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1 http://www.imsglobal.org/xsd/imscp_v1p1p3.xsd http://www.imsglobal.org/xsd/imsmd_v1p2 http://www.imsglobal.org/xsd/imsmd_v1p2p2.xsd">
-->
	<!--output-->
	<xsl:output encoding="UTF-8" method="xml" media-type="text/xml"/>
	
	<!--attributes for namespaces of various IMS CP and MD -->
	<xsl:attribute-set name="manifestNS">
		<xsl:attribute name="xsi:schemaLocation">http://www.imsglobal.org/xsd/imscp_v1p1 http://www.imsglobal.org/xsd/imscp_v1p1p3.xsd http://www.imsglobal.org/xsd/imsmd_v1p2 http://www.imsglobal.org/xsd/imsmd_v1p2p2.xsd</xsl:attribute>
	</xsl:attribute-set>


	<!--ArchObj-->
	<xsl:template match="ArchObj">
		<xsl:element name="manifest" namespace="http://www.imsglobal.org/xsd/imscp_v1p1"  use-attribute-sets="manifestNS">
			<xsl:attribute name="identifier">MANIFEST01</xsl:attribute>
			<!--overall metadata -->
				<metadata />  <!--blank metadata for now -->
			<!--organizations (can have multiple organizations) -->
			<!-- organization is a recursive structure and hence can hold the recursive FileGrp mapping as well as StructMap -->
				<organizations>
					<xsl:attribute name="default">StructMap</xsl:attribute>  <!--set StructMap mapping as the default -->
					<xsl:apply-templates select="StructMap" mode="MapToOrganization" />
				</organizations>
			<!--resources -->
			<resources>
				<xsl:apply-templates select="FileGrp" mode="MapToResource" />
			</resources>
		</xsl:element>  <!--end of manifest -->
	</xsl:template>
	
	
	<!-- Generate Resources -->
	<!--FileGrp is a recursive structure whereas Resource cannot contain another Resource.
	Right now, I will just map out the files (in METS, we can have mptr, so this type of solution is not sufficient for METS
	-->
	<xsl:template match="FileGrp" mode="MapToResource">
		<xsl:apply-templates select=".//File" mode="MapToResource" />
	</xsl:template>
	
	<xsl:template match="File" mode="MapToResource">
		<resource> 
			<xsl:attribute name="identifier"><xsl:value-of select="@ID"/></xsl:attribute>
			<xsl:attribute name="type">webcontent</xsl:attribute>  <!--webcontent is the only legal type right now -->
			<xsl:attribute name="href"><xsl:value-of select="normalize-space(FLocat)" /></xsl:attribute>
			<!--metadata (blank for now)-->
			<metadata />
			<!--for resources with only one file, one can put the file ref right into the href attrib of resource or create a file child element -->
			<!--I thought that file can be used for remote files  but the LRN viewer did not let me -->
			<!--so  I need to map it to href of resource -->
		</resource>
	</xsl:template>
	
	<!--Generate Organization -->
	<xsl:template match="StructMap" mode="MapToOrganization">
		<organization>
			<xsl:attribute name="identifier">StructMap</xsl:attribute>
			<!-- could put title and metadata here (but I don't know of a mapping for it -->
			<xsl:apply-templates select="div" mode="MapToItem"/>
		</organization>
	</xsl:template>
	
	<!-- MOA2:div to IMS:item -->
	<xsl:template match="div" mode="MapToItem">
		<item>
			<xsl:attribute name="identifier"><xsl:value-of select="generate-id(.)" /></xsl:attribute>
			<title><xsl:value-of select="@LABEL" /></title>
			<xsl:apply-templates select="fptr" mode="MapToItem"/>
			<!--recursive application of div -->
			<xsl:apply-templates select="div" mode="MapToItem"/>
		</item>
	</xsl:template>
	
	<!--MOA2:fptr to IMS:item -->
	<xsl:template match="fptr" mode="MapToItem">
		<item>
			<xsl:attribute name="identifier"><xsl:value-of select="generate-id(.)" /></xsl:attribute>
			<xsl:attribute name="identifierref"><xsl:value-of select="@FILEID" /></xsl:attribute>
			<title><xsl:value-of select="../@LABEL"/> (<xsl:value-of select="normalize-space(id(@FILEID)/@MIMETYPE)" />)</title>  <!--subjective mapping -->
			
		</item>
	</xsl:template>
	
	

</xsl:stylesheet>
