<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mt="http://www.iana.org/assignments/media-types/" xmlns:la="http://www.loc.gov/standards/iso639-2/" xmlns:str="http://exslt.org/strings" extension-element-prefixes="str" xmlns="http://www.pbcore.org/PBCore/PBCoreNamespace.html" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output encoding="UTF-8" method="xml" version="1.0" indent="yes"/>

<!--
Title: mediainfo2pbcoreinstantiation.xsl
Version: 0.1.1
Based on Mediainfo version 0.7.28
Based on PBCore version 1.2.1

	© 2010 AudioVisual Preservation Solutions
	Created to transform XML output of MediaInfo (http://mediainfo.sourceforge.net by MediaArea, SARL) to an instantiation element of a PBCore 1.2.1 record (http://www.pbcore.org). The translation expects that MediaInfo be operated with the '-f', '__Language=Raw', and '__Output=XML' options (change double-underscores to double-hyphens). The translation is customized for mediainfo version 0.7.27 and may provide unexpected results with any other version of mediainfo.
		
	Updated for use with the Secure Media Network of the Dance Heritage Coalition, September 2009.

	This work employs PBCore. The PBCore (Public Broadcasting Metadata Dictionary) was created by the public broadcasting community in the United States of America for use by public broadcasters and others. Initial development funding for PBCore was provided by the Corporation for Public Broadcasting. The PBCore is built on the foundation of the Dublin Core (ISO 15836), an international standard for resource discovery (http://dublincore.org), and has been reviewed by the Dublin Core Metadata Initiative Usage Board. Copyright: 2005, Corporation for Public Broadcasting. 

Versions:

0.1.1 initial release

		
		Example use:
		
		a. generate mediainfo.xml (change double-underscore to double-hyphen)
		
		   mediainfo -f __Language=raw __Output=XML file.mov > mediainfo.xml
		
		b. use mediainfo_2_pbcore_inst.xsl to transform mediainfo.xml to pbcore.xml
		
		   xsltproc mediainfo2pbcoreinstantiation.xsl mediainfo.xml > pbcore.xml
		   
		Or as one line:
		
		   mediainfo __Language=raw -f __Output=XML file.mov > mediainfo.xml && xsltproc mediainfo2pbcoreinstantiation.xsl mediainfo.xml > pbcore.xml
-->

	<!-- if you use the PBCore 'version' attribute, you can set it globally here and add 'xsl:use-attribute-sets="pbcore1.2.1"' to the nodes that allow it:
	<xsl:attribute-set name="pbcore1.2.1">
		<xsl:attribute name="version">PBCoreXSD_Ver_1.2_D1</xsl:attribute>
	</xsl:attribute-set> -->
	<xsl:key name="lang-lookup" match="la:lang" use="@one"/>
	<xsl:variable name="langs-top" select="document('')/*/la:langs"/>
	<xsl:template match="Mediainfo">
		<xsl:for-each select="File">
			<xsl:comment> generated by mediainfo2pbcoreinstantiation.xsl ; version 0.1.1 ; www.avpreserve.com </xsl:comment>
			<pbcoreInstantiation>
				<xsl:for-each select="track[@type='General']">
					<!-- formatIdentifier/formatIdentifierSource -->
					<xsl:if test="FileName">
						<pbcoreFormatID>
							<formatIdentifier><xsl:value-of select="FileName"/></formatIdentifier>
							<formatIdentifierSource>File Name</formatIdentifierSource>
						</pbcoreFormatID>
					</xsl:if>
					<xsl:for-each select="str:tokenize(OriginalSourceMedium, '/')"><!-- this matches the value 'Reel' in Final Cut, it's stored as a label on a Quicktime timecode track -->
						<pbcoreFormatID>
							<formatIdentifier><xsl:value-of select="normalize-space(.)"/></formatIdentifier>
							<formatIdentifierSource>Original Source Medium</formatIdentifierSource>
						</pbcoreFormatID>
					</xsl:for-each>
					<xsl:for-each select="str:tokenize(Media_UUID, '/')"><!-- this matches on the 'uuid' element in Final Cut XML Interchange Format-->
						<pbcoreFormatID>
							<formatIdentifier><xsl:value-of select="normalize-space(.)"/></formatIdentifier>
							<formatIdentifierSource>Final Cut Studio UUID</formatIdentifierSource>
						</pbcoreFormatID>
					</xsl:for-each>
					<xsl:for-each select="str:tokenize(Media_History_UUID, '/')">
						<pbcoreFormatID>
							<formatIdentifier><xsl:value-of select="normalize-space(.)"/></formatIdentifier>
							<formatIdentifierSource>Final Cut Studio UUID Item History</formatIdentifierSource>
						</pbcoreFormatID>
					</xsl:for-each>
                    <!-- dateCreated -->
					<xsl:if test="Encoded_Date">
						<dateCreated>
							<xsl:choose>
								<xsl:when test="substring(Encoded_Date,1,3)='UTC' and string-length(Encoded_Date)='23'">
									<xsl:value-of select="substring(Encoded_Date,5,10)"/><xsl:text>T</xsl:text><xsl:value-of select="substring(Encoded_Date,16,8)"/><xsl:text>Z</xsl:text>
								</xsl:when>
								<xsl:when test="string-length(Encoded_Date)='19'">
									<xsl:value-of select="substring(Encoded_Date,1,10)"/><xsl:text>T</xsl:text><xsl:value-of select="substring(Encoded_Date,12,8)"/>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="Encoded_Date"/>
								</xsl:otherwise>
							</xsl:choose>
						</dateCreated>
					</xsl:if>
					<!-- dateIssued -->				
					<xsl:if test="Released_Date"><!-- rare -->
      					<dateIssued><xsl:value-of select="Released_Date"/></dateIssued>
					</xsl:if>
					<!-- formatPhysical: is this applicable in a mapping from a digital file analysis? -->
					<!-- formatDigital -->
					<xsl:if test="InternetMediaType">
						<formatDigital><xsl:value-of select="InternetMediaType"/></formatDigital>
					</xsl:if>
					<!-- formatLocation -->
					<formatLocation><xsl:value-of select="CompleteName"/></formatLocation><!-- filepath -->
					<!-- formatMediaType -->
					<formatMediaType>
    					<xsl:choose><!-- attempts to make a guess at formatMediaType. There is no method to clarify if a file is 'Animation' vs 'Moving Image', 'Presentation' vs 'Text', etc. Only these four mediaTypes are tested for now. -->
    						<xsl:when test="VideoCount > 0">Moving Image</xsl:when>
    						<xsl:when test="AudioCount > 0">Sound</xsl:when>
    						<xsl:when test="ImageCount > 0">Static Image</xsl:when>
    						<xsl:when test="TextCount  > 0">Text</xsl:when>
    					</xsl:choose>
					</formatMediaType>
					<!-- formatGenerations this is disabled in this version. Uncomment this section to pass formatGenerations in as a stringparam in xsltproc -->
					<!-- <xsl:if test="string-length($formatGenerations)>0">
           				<formatGenerations><xsl:value-of select="$formatGenerations"/></formatGenerations>
              		</xsl:if>-->
					<!-- formatFileSize -->
					<xsl:if test="FileSize"><!-- this expresses filesize as an integer count of bytes -->
						<formatFileSize><xsl:value-of select="FileSize"/><xsl:text> bytes</xsl:text></formatFileSize>
					</xsl:if>
					<!-- formatTimeStart -->
					<xsl:choose>
						<xsl:when test="Delay_Original_String3"><formatTimeStart><xsl:value-of select="Delay_Original_String3"/></formatTimeStart></xsl:when>
						<xsl:when test="Delay_String3"><formatTimeStart><xsl:value-of select="Delay_String3"/></formatTimeStart></xsl:when>
					</xsl:choose>
					<!-- formatDuration -->
					<xsl:if test="Duration_String3"><!-- expresses duration as HH:MM:SS.mmmm -->
						<formatDuration><xsl:value-of select="Duration_String3"/></formatDuration>
					</xsl:if>
					<!-- formatDataRate --><xsl:if test="OverallBitRate"><!-- expresses bitrate as bits per second -->
						<formatDataRate><xsl:value-of select="OverallBitRate"/><xsl:text> bits/second</xsl:text></formatDataRate>
					</xsl:if>
                  	<!-- formatColors: undetermined, this value is about how the video color is presented, not stored -->			
					<!-- formatTracks -->
					<xsl:variable name='track'>
    					<xsl:if test="VideoCount">
      						<xsl:value-of select="VideoCount"/><xsl:text> video track</xsl:text><xsl:if test="VideoCount&gt;1">s</xsl:if><xsl:text>, </xsl:text>
						</xsl:if>
						<xsl:if test="AudioCount">
      						<xsl:value-of select="AudioCount"/><xsl:text> audio track</xsl:text><xsl:if test="AudioCount&gt;1">s</xsl:if><xsl:text>, </xsl:text>
						</xsl:if>
						<xsl:if test="TextCount">
      						<xsl:value-of select="TextCount"/><xsl:text> text track</xsl:text><xsl:if test="TextCount&gt;1">s</xsl:if><xsl:text>, </xsl:text>
						</xsl:if>
					</xsl:variable>
					<formatTracks>
						<xsl:value-of select="substring($track,1,string-length($track)-2)"/>
					</formatTracks>				
					<!-- formatChannelConfiguration -->
					<xsl:if test="AudioCount>0"><!-- results aren't very interesting without audio configuration data -->
    					<xsl:variable name='fCC_audio'>
            					<xsl:for-each select="../track[@type='Audio']"><xsl:value-of select="Format"/><xsl:if test='ChannelPositions'><xsl:text> (</xsl:text><xsl:value-of select="ChannelPositions"/><xsl:text>)</xsl:text></xsl:if><xsl:text>, </xsl:text></xsl:for-each>
    					</xsl:variable>
    					<xsl:variable name='fCC_text'>
            					<xsl:for-each select="../track[@type='Text']"><xsl:value-of select="Format"/><xsl:if test='Language'><xsl:text> (</xsl:text><xsl:apply-templates select="$langs-top"><xsl:with-param name="curr-language" select="Language"/></xsl:apply-templates><xsl:text>)</xsl:text></xsl:if><xsl:text>, </xsl:text></xsl:for-each>
    					</xsl:variable>
    					<xsl:variable name='formatChannelConfigurations'>
        					<xsl:if test="Video_Format_WithHint_List"><xsl:value-of select="Video_Format_WithHint_List"/> with </xsl:if>
    						<xsl:if test="Audio_Format_WithHint_List">
          						<xsl:value-of select="substring($fCC_audio,1,string-length($fCC_audio)-2)"/><xsl:text> with </xsl:text>
    						</xsl:if>
    						<xsl:if test="Text_Format_WithHint_List">
        						<xsl:value-of select="substring($fCC_text,1,string-length($fCC_text)-2)"/><xsl:text> with </xsl:text>
    						</xsl:if>
    						<xsl:if test="Image_Format_WithHint_List"><xsl:value-of select="Image_Format_WithHint_List"/> with </xsl:if>
    						<xsl:if test="Menu_Format_WithHint_List"><xsl:value-of select="Menu_Format_WithHint_List"/> with </xsl:if>
    					</xsl:variable>
    					<formatChannelConfiguration>
    						<xsl:value-of select="substring($formatChannelConfigurations,1,string-length($formatChannelConfigurations)-6)"/>
    					</formatChannelConfiguration>
					</xsl:if>
					<!-- language -->
    				<xsl:if test="Language"><!-- retrieves MediaInfo's language values in ISO639-1 and converts them to ISO639-2 -->
    					<language>
    						<xsl:apply-templates select="$langs-top">
    							<xsl:with-param name="curr-language" select="Language"/>
    						</xsl:apply-templates>
    					</language>
    				</xsl:if>
    				<!-- alternativeModes: nothing inferred here yet -->
    				<!-- essenceTrack -->
    				</xsl:for-each>
    				<xsl:for-each select="track[@type!='General']">
    				  <pbcoreEssenceTrack>
    				    <!-- essenceTrackType -->
    				    <essenceTrackType>
        					<xsl:choose><!-- some translation of reported trackType, else reported as is -->
        						<xsl:when test="Format='TimeCode'">timecode</xsl:when>
        						<xsl:when test="Format='EIA-608' or Format='EIA-708'">caption</xsl:when>
        						<xsl:when test="../track[@type='Text']/Format='Apple text|ASS|DivX Subtitle|DVB Subtitles|PGS|SSA|Teletext|Text|Subrip|SubRip|Timed text|USF|VobSub'">subtitle</xsl:when>
        						<xsl:when test="Format='CMML'">metadata</xsl:when>
        						<xsl:otherwise><xsl:value-of select="@type"/></xsl:otherwise>
        					</xsl:choose>
    					</essenceTrackType>
    					<!-- essenceTrackIdentifier/essenceTrackIdentifierSource -->
    				    <xsl:choose><!-- essenceTrackIdenfier may only occur once, although it is not required it seems to be generally best practice to have one, although with some file types this concept doesn't really exist. This method prefers to take the reported track ID else just uses a counter for that trackType (which means it could repeat within the same instantiation. ... -->
    				    	<xsl:when test="ID">
    						    <essenceTrackIdentifier><xsl:value-of select="ID"/></essenceTrackIdentifier>
    						    <essenceTrackIdentifierSource>ID (Mediainfo)</essenceTrackIdentifierSource>
    					    </xsl:when>
    				    	<xsl:when test="StreamKindID">
    						    <essenceTrackIdentifier><xsl:value-of select="StreamKindID"/></essenceTrackIdentifier>
    						    <essenceTrackIdentifierSource>StreamKindID (Mediainfo)</essenceTrackIdentifierSource>
    				   		</xsl:when>
    				   	</xsl:choose>
    				   	<!-- essenceTrackStandard -->
    				    <xsl:if test="Standard">
    				    	<essenceTrackStandard><xsl:value-of select="Standard"/></essenceTrackStandard>
    				    </xsl:if>
    				    <!-- essenceTrackEncoding -->
    				    <xsl:if test="Format"><!-- not sure how best to handle encoding, feel free to remove the extra xsl:if statements to reduce verbosity -->
    					    <essenceTrackEncoding>
    					    <xsl:choose>
        					    <xsl:when test="Format='Digital Video'"><xsl:text>DV</xsl:text></xsl:when>
        					    <xsl:otherwise><xsl:value-of select="Format"/></xsl:otherwise>
    					    </xsl:choose>
    					    <xsl:if test="Format_Version">
    						    <xsl:text> </xsl:text><xsl:value-of select="Format_Version"/>
    					    </xsl:if>
    					    <xsl:if test="Format_Profile">
    						    <xsl:text> </xsl:text><xsl:value-of select="Format_Profile"/>
    					    </xsl:if>
    					    <xsl:if test="Format_Settings_Endianness">
    						    <xsl:text> </xsl:text><xsl:value-of select="Format_Settings_Endianness"/><xsl:text>-endian</xsl:text>
    					    </xsl:if>
    					    <xsl:if test="Format_Settings_Sign">
    						    <xsl:text> </xsl:text><xsl:value-of select="Format_Settings_Sign"/>
    					    </xsl:if>
    					   	<xsl:if test="CodecID and CodecID!=Format">
    						    <xsl:text> (</xsl:text><xsl:value-of select="CodecID"/><xsl:text>)</xsl:text>
    					    </xsl:if>
    					    </essenceTrackEncoding>
    				    </xsl:if>
    				    <!-- essenceTrackDataRate -->
    				    <xsl:if test="BitRate">
    					    <essenceTrackDataRate><xsl:value-of select="BitRate"/><xsl:text> bits/second</xsl:text></essenceTrackDataRate>
    				    </xsl:if>
    				    <!-- essenceTrackTimeStart -->
    				    <xsl:choose>
    						<xsl:when test="Delay_Original_String3">
    							<essenceTimeStart><xsl:value-of select="Delay_Original_String3"/></essenceTimeStart>
    						</xsl:when>
    						<xsl:when test="Delay_String3">
    							<essenceTimeStart><xsl:value-of select="Delay_String3"/></essenceTimeStart>
    						</xsl:when>
						<!-- essenceTrackDuration -->
    					</xsl:choose>
    				    <xsl:if test="Duration_String3">
    					    <essenceTrackDuration><xsl:value-of select="Duration_String3"/></essenceTrackDuration>
    				    </xsl:if>
    				    <!-- essenceTrackBitDepth -->
    					<xsl:if test="Resolution">
    					    <essenceTrackBitDepth><xsl:value-of select="Resolution"/><xsl:text> bit</xsl:text></essenceTrackBitDepth>
    					</xsl:if>
    					<!-- essenceTrackSamplingRate -->
    				    <xsl:if test="SamplingRate">
    					    <essenceTrackSamplingRate><xsl:value-of select="SamplingRate div 1000"/><xsl:text> kHz</xsl:text></essenceTrackSamplingRate>
    				    </xsl:if>
    				    <!-- essenceTrackFrameSize -->
    				    <xsl:if test="Width">
    					    <essenceTrackFrameSize><xsl:value-of select="Width"/><xsl:text>x</xsl:text><xsl:value-of select="Height"/></essenceTrackFrameSize>
    				    </xsl:if>
    				    <!-- essenceTrackAspectRatio: as displayed not stored -->
    				    <xsl:if test="DisplayAspectRatio_String">
    					    <essenceTrackAspectRatio><xsl:value-of select="DisplayAspectRatio_String"/></essenceTrackAspectRatio>
    				    </xsl:if>
    				    <!-- essenceTrackFrameRate -->
    				    <xsl:if test="FrameRate">
              			    <essenceTrackFrameRate><xsl:value-of select="FrameRate"/><xsl:text> fps</xsl:text></essenceTrackFrameRate>
    				    </xsl:if>
    				    <!-- essenceTrackLanguage -->
    				    <xsl:if test="Language">
    						<essenceTrackLanguage>
    							<xsl:apply-templates select="$langs-top">
    								<xsl:with-param name="curr-language" select="Language"/>
    							</xsl:apply-templates>
    						</essenceTrackLanguage>
    					</xsl:if>
    					<!-- essenceTrackAnnotation -->
    				    <essenceTrackAnnotation>
    				    <!-- the following potential annotations from MediaInfo are renamed for PBCore -->
    				    <xsl:if test="Colorimetry">
    					    <xsl:text>Chroma-subsampling: </xsl:text><xsl:value-of select="Colorimetry"/><xsl:text>&#xa;</xsl:text>
    				    </xsl:if>
    				    <xsl:if test="Channel_s_">
    					    <xsl:text>Channels: </xsl:text><xsl:value-of select="Channel_s_"/><xsl:text>&#xa;</xsl:text>
    				    </xsl:if>
    				    <xsl:if test="Bits-_Pixel_Frame_">
    					    <xsl:text>BitsPerPixel: </xsl:text><xsl:value-of select="Bits-_Pixel_Frame_"/><xsl:text>&#xa;</xsl:text>
    				    </xsl:if>
    				    <xsl:if test="Delay_Settings"><!-- note occasionally a codec and container can have conflicting timecode setting data -->
    					    <xsl:text>TimecodeSettings_Container: </xsl:text><xsl:value-of select="Delay_Settings"/><xsl:text>&#xa;</xsl:text>
    				    </xsl:if>
    				    <xsl:if test="Delay_Original_Settings">
    					    <xsl:text>TimecodeSettings_Codec: </xsl:text><xsl:value-of select="Delay_Original_Settings"/><xsl:text>&#xa;</xsl:text>
    				    </xsl:if>
    
    				    <!-- unlike annotations of the instantiation element, the essenceTrackAnnotation may only occur once per essenceTrack. This approach excludes MediaInfo values that are mapped elsewhere, depreciated, or redundant and then states the remaining essenceTrack values in a concatenated string within a single essenceTrack element with line breaks separating each value. This produces a very verbose reporting on essenceTrack data. -->
					    <xsl:for-each select="*">
							<xsl:if test="name(.)!='Count' and name(.)!='StreamCount' and name(.)!='StreamKind' and name(.)!='StreamKind_String' and name(.)!='StreamKindID' and name(.)!='StreamKindPos' and name(.)!='Inform' and name(.)!='ID' and name(.)!='ID_String' and name(.)!='Format_Info' and name(.)!='Format_URL' and name(.)!='Format_Settings_SBR_String' and name(.)!='Format_Settings_PS_String' and name(.)!='Format_Version' and name(.)!='Format_Profile' and name(.)!='CodecID_Info' and name(.)!='CodecID_Hint' and name(.)!='CodecID_Url' and name(.)!='CodecID_Description' and name(.)!='Codec' and name(.)!='Codec_String' and name(.)!='Codec_Family' and name(.)!='Codec_Info' and name(.)!='Codec_Url' and name(.)!='Codec_CC' and name(.)!='Codec_Profile' and name(.)!='Codec_Description' and name(.)!='Codec_Profile' and name(.)!='Codec_Settings' and name(.)!='Codec_Settings_Automatic' and name(.)!='Codec_Settings_Floor' and name(.)!='Codec_Settings_Firm' and name(.)!='Codec_Settings_Endianness' and name(.)!='Codec_Settings_Sign' and name(.)!='Codec_Settings_Law' and name(.)!='Codec_Settings_ITU' and name(.)!='Codec_Settings_BVOP' and name(.)!='Codec_Settings_QPel' and name(.)!='Codec_Settings_GMC' and name(.)!='Codec_Settings_GMC_String' and name(.)!='Codec_Settings_Matrix' and name(.)!='Codec_Settings_Matrix_Data' and name(.)!='Codec_Settings_CABAC' and name(.)!='Codec_Settings_RefFrames' and name(.)!='Duration' and name(.)!='Duration_String' and name(.)!='Duration_String1' and name(.)!='Duration_String2' and name(.)!='Duration_String3' and name(.)!='BitRate_Mode_String' and name(.)!='BitRate' and name(.)!='BitRate_String' and name(.)!='lBitRate_Minimum_String' and name(.)!='BitRate_Nominal_String' and name(.)!='BitRate_Maximum_String' and name(.)!='Channel_s__String' and name(.)!='ChannelPositions_String2' and name(.)!='SamplingRate' and name(.)!='SamplingRate_String' and name(.)!='Width' and name(.)!='Width_String' and name(.)!='Height' and name(.)!='Height_String' and name(.)!='PixelAspectRatio_String' and name(.)!='PixelAspectRatio_Original_String' and name(.)!='DisplayAspectRatio_String' and name(.)!='DisplayAspectRatio_Original_String' and name(.)!='FrameRate' and name(.)!='FrameRate_String' and name(.)!='FrameRate_Minimum_String' and name(.)!='FrameRate_Nominal_String' and name(.)!='FrameRate_Maximum_String' and name(.)!='FrameRate_Original_String' and name(.)!='Resolution' and name(.)!='Resolution_String' and name(.)!='ScanType_String' and name(.)!='ScanOrder_String' and name(.)!='Interlacement' and name(.)!='Interlacement_String' and name(.)!='Delay' and name(.)!='Delay_String' and name(.)!='Delay_String1' and name(.)!='Delay_String2' and name(.)!='Delay_String3' and name(.)!='Delay_Original' and name(.)!='Delay_Original_String' and name(.)!='Delay_Original_String1' and name(.)!='Delay_Original_String2' and name(.)!='Delay_Original_String3' and name(.)!='Video_Delay' and name(.)!='Video_Delay_String' and name(.)!='Video_Delay_String1' and name(.)!='Video_Delay_String2' and name(.)!='Video_Delay_String3' and name(.)!='Video0_Delay' and name(.)!='Video0_Delay_String' and name(.)!='Video0_Delay_String1' and name(.)!='Video0_Delay_String2' and name(.)!='Video0_Delay_String3' and name(.)!='ReplayGain_Gain_String' and name(.)!='Interleave_Duration_String' and name(.)!='Interleave_Preload_String' and name(.)!='StreamSize_String' and name(.)!='StreamSize_String1' and name(.)!='StreamSize_String2' and name(.)!='StreamSize_String3' and name(.)!='StreamSize_String4' and name(.)!='StreamSize_String5' and name(.)!='Alignment_String' and name(.)!='Encoded_Application_Url' and name(.)!='Encoded_Library_String' and name(.)!='Language' and name(.)!='Language_String' and name(.)!='Colorimetry' and name(.)!='Format' and name(.)!='Format_Settings' and name(.)!='Format_Settings_Endianness' and name(.)!='Format_Settings_Sign' and name(.)!='InternetMediaType' and name(.)!='CodecID' and name(.)!='Standard' and name(.)!='FolderName' and name(.)!='Channel_s_' and name(.)!='FrameRate_Mode_String' and name(.)!='Bits-_Pixel_Frame_' and name(.)!='Delay_Settings' and name(.)!='Delay_Original_Settings' and name(.)!='MenuID_String' and name(.)!='Format_Url' and name(.)!='Format_Settings_CABAC_String' and name(.)!='Format_Settings_RefFrames_String' and name(.)!='FrameRate_Mode_String' and name(.)!='Encoded_Library'">		       
        				       		<xsl:value-of select="local-name(.)"/><xsl:text>: </xsl:text>
								<xsl:choose>
									<xsl:when test="substring(.,1,3)='UTC' and string-length(.)='23'">
										<xsl:value-of select="substring(.,5,10)"/><xsl:text>T</xsl:text><xsl:value-of select="substring(.,16,8)"/><xsl:text>Z</xsl:text>
									</xsl:when>
									<xsl:when test="string-length(.)='19'">
										<xsl:value-of select="substring(.,1,10)"/><xsl:text>T</xsl:text><xsl:value-of select="substring(.,12,8)"/>
									</xsl:when>
									<xsl:otherwise>
										<xsl:value-of select="."/>
									</xsl:otherwise>
								</xsl:choose>
								<xsl:text>&#xa;</xsl:text>
						    </xsl:if>
						</xsl:for-each>
				    </essenceTrackAnnotation>
				  </pbcoreEssenceTrack>
				</xsl:for-each>
				<!-- annotations: there seems to be 2 ways to go about handling annotations in a MediaInfo to pbcore-instantiation workflow: 1). inclusive and 2). exclusive. The below method goes with an exclusive approach where MediaInfo values that aren't specifically mapped elsewhere are retained while depreciated and redundant values are also excluded. Feel free to tinker with the test attribute in the xsl:if element to adjust the verbosity. An alternate inclusive approach is commented out just below this. -->
				<xsl:for-each select="track[@type='General']">
					<xsl:if test="Format">
						<pbcoreAnnotation>
					        <annotation>
					       		<xsl:text>Container: </xsl:text><xsl:value-of select="Format"/>
					       		<xsl:if test="Format_Version">
								    <xsl:text> </xsl:text><xsl:value-of select="Format_Version"/>
							    </xsl:if>
							    <xsl:if test="Format_Profile">
								    <xsl:text> </xsl:text><xsl:value-of select="Format_Profile"/>
							    </xsl:if>
							   	<xsl:if test="CodecID"><!-- fourcc codes are helpful but don't have an explicit location in pbcore. Current these are stored parathetically within essenceTrackEncoding and 'Container' annotations but potentially these could be handled separately as their own annotation. -->
								    <xsl:text> (</xsl:text><xsl:value-of select="CodecID"/><xsl:text>)</xsl:text>
							    </xsl:if>
							</annotation>
						</pbcoreAnnotation>
					</xsl:if>
					<xsl:for-each select="*">
						<xsl:if test="name(.)!='Count' and name(.)!='StreamCount' and name(.)!='StreamKind' and name(.)!='StreamKind_String' and name(.)!='StreamKindID' and name(.)!='StreamKindPos' and name(.)!='Inform' and name(.)!='ID_String' and name(.)!='UniqueID_String' and name(.)!='GeneralCount' and name(.)!='VideoCount' and name(.)!='AudioCount' and name(.)!='TextCount' and name(.)!='ChaptersCount' and name(.)!='ImageCount' and name(.)!='MenuCount' and name(.)!='Video_Format_List' and name(.)!='Video_Language_List' and name(.)!='Video_Format_WithHint_List' and name(.)!='Video_Codec_List' and name(.)!='Audio_Format_List' and name(.)!='Audio_Language_List' and name(.)!='Audio_Format_WithHint_List' and name(.)!='Audio_Codec_List' and name(.)!='Text_Format_List' and name(.)!='Text_Language_List' and name(.)!='Text_Format_WithHint_List' and name(.)!='Text_Codec_List' and name(.)!='Chapters_Format_List' and name(.)!='Chapters_Language_List' and name(.)!='Chapters_Format_WithHint_List' and name(.)!='Chapters_Codec_List' and name(.)!='Image_Format_List' and name(.)!='Image_Language_List' and name(.)!='Image_Format_WithHint_List' and name(.)!='Image_Codec_List' and name(.)!='Menu_Format_List' and name(.)!='Menu_Language_List' and name(.)!='Menu_Format_WithHint_List' and name(.)!='Menu_Codec_List' and name(.)!='FileName' and name(.)!='Format' and name(.)!='Format_Extensions' and name(.)!='Format_Version' and name(.)!='Format_Profile' and name(.)!='Format_String' and name(.)!='Format_Url' and name(.)!='CodecID' and name(.)!='Codec' and name(.)!='Codec_String' and name(.)!='Codec_Info' and name(.)!='Codec_Url' and name(.)!='CodecID_Url' and name(.)!='Codec_Extensions' and name(.)!='Codec_Settings' and name(.)!='Codec_Settings_Automatic' and name(.)!='OriginalSourceMedium' and name(.)!='com.apple.finalcutstudio.media.uuid' and name(.)!='CompleteName' and name(.)!='FileSize' and name(.)!='FileSize_String' and name(.)!='FileSize_String1' and name(.)!='FileSize_String2' and name(.)!='FileSize_String3' and name(.)!='FileSize_String4' and name(.)!='Delay_Original_String3' and name(.)!='Delay_String3' and name(.)!='Duration' and name(.)!='Duration_String' and name(.)!='Duration_String1' and name(.)!='Duration_String2' and name(.)!='Duration_String3' and name(.)!='OverallBitRate_Mode_String' and name(.)!='OverallBitRate' and name(.)!='OverallBitRate_String' and name(.)!='OverallBitRate_Minimum_String' and name(.)!='OverallBitRate_Nominal_String' and name(.)!='OverallBitRate_Maximum_String' and name(.)!='StreamSize' and name(.)!='StreamSize_Proportion' and name(.)!='StreamSize_String' and name(.)!='StreamSize_String1' and name(.)!='StreamSize_String2' and name(.)!='StreamSize_String3' and name(.)!='StreamSize_String4' and name(.)!='StreamSize_String5' and name(.)!='com.apple.quicktime.player.movie.audio.mute' and name(.)!='Encoded_Library_String' and name(.)!='Encoded_Library_Name' and name(.)!='Encoded_Library_Version' and name(.)!='Cover_Data' and name(.)!='Language' and name(.)!='Language_String' and name(.)!='InternetMediaType' and name(.)!='FileExtension' and name(.)!='Media_UUID' and name(.)!='Media_History_UUID' and name(.)!='FolderName'">
						    <pbcoreAnnotation>
						        <annotation>       		
							       	<xsl:value-of select="local-name(.)"/><xsl:text>: </xsl:text><!-- the annotation as named by MediaInfo's raw output -->				    
									<xsl:choose>
										<xsl:when test="substring(.,1,3)='UTC' and string-length(.)='23'">
											<xsl:value-of select="substring(.,5,10)"/><xsl:text>T</xsl:text><xsl:value-of select="substring(.,16,8)"/><xsl:text>Z</xsl:text>
										</xsl:when>
									    <xsl:when test="string-length(.)='19'">
										<xsl:value-of select="substring(.,1,10)"/><xsl:text>T</xsl:text><xsl:value-of select="substring(.,12,8)"/>
										</xsl:when>
										<xsl:otherwise>
											<xsl:value-of select="."/>
										</xsl:otherwise>
									</xsl:choose>
								</annotation>
						    </pbcoreAnnotation>
					    </xsl:if>
					</xsl:for-each>
				</xsl:for-each>
			</pbcoreInstantiation>
		</xsl:for-each>	
	</xsl:template>	
	<xsl:template match="la:langs">
		<xsl:param name="curr-language"/>
		<xsl:value-of select="key('lang-lookup', $curr-language)/@two"/>
	</xsl:template>
	<la:langs>
		<la:lang one="aa" two="aar"/>		<la:lang one="ab" two="abk"/>		<la:lang one="ae" two="ave"/>		<la:lang one="af" two="afr"/>		<la:lang one="ak" two="aka"/>		<la:lang one="am" two="amh"/>		<la:lang one="an" two="arg"/>		<la:lang one="ar" two="ara"/>		<la:lang one="as" two="asm"/>		<la:lang one="av" two="ava"/>		<la:lang one="ay" two="aym"/>		<la:lang one="az" two="aze"/>		<la:lang one="ba" two="bak"/>		<la:lang one="be" two="bel"/>		<la:lang one="bg" two="bul"/>		<la:lang one="bh" two="bih"/>		<la:lang one="bi" two="bis"/>		<la:lang one="bm" two="bam"/>		<la:lang one="bn" two="ben"/>		<la:lang one="bo" two="tib"/>		<la:lang one="br" two="bre"/>		<la:lang one="bs" two="bos"/>		<la:lang one="ca" two="cat"/>		<la:lang one="ce" two="che"/>		<la:lang one="ch" two="cha"/>		<la:lang one="co" two="cos"/>		<la:lang one="cr" two="cre"/>		<la:lang one="cs" two="cze"/>		<la:lang one="cu" two="chu"/>		<la:lang one="cv" two="chv"/>		<la:lang one="cy" two="wel"/>		<la:lang one="da" two="dan"/>		<la:lang one="de" two="ger"/>		<la:lang one="dv" two="div"/>		<la:lang one="dz" two="dzo"/>		<la:lang one="ee" two="ewe"/>		<la:lang one="el" two="gre"/>		<la:lang one="en" two="eng"/>		<la:lang one="eo" two="epo"/>		<la:lang one="es" two="spa"/>		<la:lang one="et" two="est"/>		<la:lang one="eu" two="baq"/>		<la:lang one="fa" two="per"/>		<la:lang one="ff" two="ful"/>		<la:lang one="fi" two="fin"/>		<la:lang one="fj" two="fij"/>		<la:lang one="fo" two="fao"/>		<la:lang one="fr" two="fre"/>		<la:lang one="fy" two="fry"/>		<la:lang one="ga" two="gle"/>		<la:lang one="gd" two="gla"/>		<la:lang one="gl" two="glg"/>		<la:lang one="gn" two="grn"/>		<la:lang one="gu" two="guj"/>		<la:lang one="gv" two="glv"/>		<la:lang one="ha" two="hau"/>		<la:lang one="he" two="heb"/>		<la:lang one="hi" two="hin"/>		<la:lang one="ho" two="hmo"/>		<la:lang one="hr" two="hrv"/>		<la:lang one="ht" two="hat"/>		<la:lang one="hu" two="hun"/>		<la:lang one="hy" two="arm"/>		<la:lang one="hz" two="her"/>		<la:lang one="ia" two="ina"/>		<la:lang one="id" two="ind"/>		<la:lang one="ie" two="ile"/>		<la:lang one="ig" two="ibo"/>		<la:lang one="ii" two="iii"/>		<la:lang one="ik" two="ipk"/>		<la:lang one="io" two="ido"/>		<la:lang one="is" two="ice"/>		<la:lang one="it" two="ita"/>		<la:lang one="iu" two="iku"/>		<la:lang one="ja" two="jpn"/>		<la:lang one="jv" two="jav"/>		<la:lang one="ka" two="geo"/>		<la:lang one="kg" two="kon"/>		<la:lang one="ki" two="kik"/>		<la:lang one="kj" two="kua"/>		<la:lang one="kk" two="kaz"/>		<la:lang one="kl" two="kal"/>		<la:lang one="km" two="khm"/>		<la:lang one="kn" two="kan"/>		<la:lang one="ko" two="kor"/>		<la:lang one="kr" two="kau"/>		<la:lang one="ks" two="kas"/>		<la:lang one="ku" two="kur"/>		<la:lang one="kv" two="kom"/>		<la:lang one="kw" two="cor"/>		<la:lang one="ky" two="kir"/>		<la:lang one="la" two="lat"/>		<la:lang one="lb" two="ltz"/>		<la:lang one="lg" two="lug"/>		<la:lang one="li" two="lim"/>		<la:lang one="ln" two="lin"/>		<la:lang one="lo" two="lao"/>		<la:lang one="lt" two="lit"/>		<la:lang one="lu" two="lub"/>		<la:lang one="lv" two="lav"/>		<la:lang one="mg" two="mlg"/>		<la:lang one="mh" two="mah"/>		<la:lang one="mi" two="mao"/>		<la:lang one="mk" two="mac"/>		<la:lang one="ml" two="mal"/>		<la:lang one="mn" two="mon"/>		<la:lang one="mr" two="mar"/>		<la:lang one="ms" two="may"/>		<la:lang one="mt" two="mlt"/>		<la:lang one="my" two="bur"/>		<la:lang one="na" two="nau"/>		<la:lang one="nb" two="nob"/>		<la:lang one="nd" two="nde"/>		<la:lang one="ne" two="nep"/>		<la:lang one="ng" two="ndo"/>		<la:lang one="nl" two="dut"/>		<la:lang one="nn" two="nno"/>		<la:lang one="no" two="nor"/>		<la:lang one="nr" two="nbl"/>		<la:lang one="nv" two="nav"/>		<la:lang one="ny" two="nya"/>		<la:lang one="oc" two="oci"/>		<la:lang one="oj" two="oji"/>		<la:lang one="om" two="orm"/>		<la:lang one="or" two="ori"/>		<la:lang one="os" two="oss"/>		<la:lang one="pa" two="pan"/>		<la:lang one="pi" two="pli"/>		<la:lang one="pl" two="pol"/>		<la:lang one="ps" two="pus"/>		<la:lang one="pt" two="por"/>		<la:lang one="qu" two="que"/>		<la:lang one="rm" two="roh"/>		<la:lang one="rn" two="run"/>		<la:lang one="ro" two="rum"/>		<la:lang one="ru" two="rus"/>		<la:lang one="rw" two="kin"/>		<la:lang one="sa" two="san"/>		<la:lang one="sc" two="srd"/>		<la:lang one="sd" two="snd"/>		<la:lang one="se" two="sme"/>		<la:lang one="sg" two="sag"/>		<la:lang one="si" two="sin"/>		<la:lang one="sk" two="slo"/>		<la:lang one="sl" two="slv"/>		<la:lang one="sm" two="smo"/>		<la:lang one="sn" two="sna"/>		<la:lang one="so" two="som"/>		<la:lang one="sq" two="alb"/>		<la:lang one="sr" two="srp"/>		<la:lang one="ss" two="ssw"/>		<la:lang one="st" two="sot"/>		<la:lang one="su" two="sun"/>		<la:lang one="sv" two="swe"/>		<la:lang one="sw" two="swa"/>		<la:lang one="ta" two="tam"/>		<la:lang one="te" two="tel"/>		<la:lang one="tg" two="tgk"/>		<la:lang one="th" two="tha"/>		<la:lang one="ti" two="tir"/>		<la:lang one="tk" two="tuk"/>		<la:lang one="tl" two="tgl"/>		<la:lang one="tn" two="tsn"/>		<la:lang one="to" two="ton"/>		<la:lang one="tr" two="tur"/>		<la:lang one="ts" two="tso"/>		<la:lang one="tt" two="tat"/>		<la:lang one="tw" two="twi"/>		<la:lang one="ty" two="tah"/>		<la:lang one="ug" two="uig"/>		<la:lang one="uk" two="ukr"/>		<la:lang one="ur" two="urd"/>		<la:lang one="uz" two="uzb"/>		<la:lang one="ve" two="ven"/>		<la:lang one="vi" two="vie"/>		<la:lang one="vo" two="vol"/>		<la:lang one="wa" two="wln"/>		<la:lang one="wo" two="wol"/>		<la:lang one="xh" two="xho"/>		<la:lang one="yi" two="yid"/>		<la:lang one="yo" two="yor"/>		<la:lang one="za" two="zha"/>		<la:lang one="zh" two="chi"/>		<la:lang one="zu" two="zul"/>
	</la:langs>
</xsl:stylesheet>