<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE stylesheet [
<!ENTITY nbsp "<xsl:text disable-output-escaping="yes"
xmlns:xsl= "http://www.w3.org/1999/XSL/Transform "
>&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:imscp="http://www.imsglobal.org/xsd/imscp_v1p1" xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/TR/xlink" xmlns:METS="http://www.loc.gov/METS/" >
<!--output-->
<xsl:output encoding="UTF-8" method="xml" media-type="text/xml"/>
<!--attributes for namespaces of various IMS CP and MD and METS-->
<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 http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd</xsl:attribute>
</xsl:attribute-set>
<!-- METS:mets -->
<xsl:template match="METS:mets">
<xsl:element name="manifest" namespace="http://www.imsglobal.org/xsd/imscp_v1p1" use-attribute-sets="manifestNS">
<xsl:attribute name="identifier">MANIFEST01</xsl:attribute>
<metadata /> <!-- blank 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="METS:structMap" mode="MapToOrganization" />
<!-- Would be also good to map the fileSec to a secondary Organization (instead of just flattening it out into the Resources -->
<xsl:apply-templates select="METS:fileSec" mode="MapToOrganization" />
</organizations>
<!--resources -->
<resources>
<xsl:apply-templates select="METS:fileSec" mode="MapToResources" />
</resources>
</xsl:element>
</xsl:template>
<!--Generate Organization (from structMap) -->
<xsl:template match="METS: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="METS:div" mode="MapToItem"/>
</organization>
</xsl:template>
<!-- METS:div to IMS:item -->
<xsl:template match="METS: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="METS:fptr" mode="MapToItem"/>
<!--recursive application of div -->
<xsl:apply-templates select="METS:div" mode="MapToItem"/>
</item>
</xsl:template>
<!--METS:fptr to IMS:item -->
<xsl:template match="METS: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>
<!-- 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="METS:fileSec" mode="MapToResources" >
<xsl:apply-templates select="METS:fileGrp" mode="MapToResource" />
</xsl:template>
<xsl:template match="METS:fileGrp" mode="MapToResource">
<xsl:apply-templates select=".//METS:file" mode="MapToResource" />
</xsl:template>
<xsl:template match="METS: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(METS:FLocat/@xlink:href)" /></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>
</xsl:stylesheet>
