<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="NewsML">
    <xsl:variable name="avcomponent" select="NewsItem/NewsComponent[@Duid='wrapper']/NewsComponent[@Duid='video']/NewsComponent|NewsItem/NewsComponent[@Duid='wrapper']/NewsComponent[@Duid='audio']/NewsComponent"/>
    <xsl:variable name="textcomponent" select="NewsItem/NewsComponent[@Duid='wrapper']/NewsComponent[@Duid='text']"/>
    <cmml>
      <stream>
        <!-- inserting link to media file and its timing information -->
        <media>
          <xsl:attribute name="location">
            <xsl:value-of select="$avcomponent/ContentItem/@Href"/>
          </xsl:attribute>
          <xsl:attribute name="start">
            <xsl:text>0</xsl:text>
          </xsl:attribute>
          <xsl:attribute name="end">
            <xsl:value-of select="$avcomponent/ContentItem/Characteristics/Property[@FormalName='TotalDuration']/@Value"/>
          </xsl:attribute>
        </media>
      </stream>

      <head>
        <title>
          <xsl:value-of select="$avcomponent/NewsLines/HeadLine"/>
        </title>
      </head>

      <!-- inserting an anchor element -->
      <a>
	<xsl:attribute name="id">
	  <xsl:value-of select="NewsItem/Identification/NewsIdentifier/NewsItemId"/>
	</xsl:attribute>
	<xsl:attribute name="hrefdesc">
	  <xsl:value-of select="$avcomponent/NewsLines/HeadLine"/>
	</xsl:attribute>
        <xsl:attribute name="start">
          <xsl:text>0</xsl:text>
        </xsl:attribute>
        <!-- inserting meta elements -->
        <!-- Dublin Core first -->
        <meta>
          <xsl:attribute name="name">
            <xsl:text>DC.audience</xsl:text>
          </xsl:attribute>
          <xsl:attribute name="content">
            <xsl:text>General</xsl:text>
          </xsl:attribute>
        </meta>
        <meta>
          <xsl:attribute name="name">
            <xsl:text>DC.title</xsl:text>
          </xsl:attribute>
          <xsl:attribute name="content">
            <xsl:value-of select="NewsEnvelope/NewsProduct/@FormalName"/>
            <xsl:text> - </xsl:text>
            <xsl:value-of select="$textcomponent/NewsLines/DateLine"/>
          </xsl:attribute>
        </meta>
        <meta>
          <xsl:attribute name="name">
            <xsl:text>DC.author</xsl:text>
          </xsl:attribute>
          <xsl:attribute name="content">
            <xsl:value-of select="$avcomponent/NewsLines/ByLine"/>
          </xsl:attribute>
        </meta>
        <meta>
          <xsl:attribute name="name">
            <xsl:text>DC.date.created</xsl:text>
          </xsl:attribute>
          <xsl:attribute name="content">
            <xsl:value-of select="NewsItem/Identification/NewsIdentifier/DateId"/>
          </xsl:attribute>
        </meta>
<!-- confuses panoptic
        <meta>
          <xsl:attribute name="name">
            <xsl:text>DC.date.issued</xsl:text>
          </xsl:attribute>
          <xsl:attribute name="content">
            <xsl:value-of select="NewsItem/NewsManagement/ThisRevisionCreated"/>
          </xsl:attribute>
        </meta>
-->
        <meta>
          <xsl:attribute name="name">
            <xsl:text>DC.description</xsl:text>
          </xsl:attribute>
          <xsl:attribute name="content">
            <xsl:value-of select="$textcomponent/ContentItem/DataContent"/>
          </xsl:attribute>
        </meta>
        <meta>
          <xsl:attribute name="name">
            <xsl:text>DC.format</xsl:text>
          </xsl:attribute>
          <xsl:attribute name="content">
            <xsl:value-of select="$avcomponent/ContentItem/MediaType/@FormalName"/>
          </xsl:attribute>
        </meta>
        <meta>
          <xsl:attribute name="name">
            <xsl:text>DC.language</xsl:text>
          </xsl:attribute>
          <xsl:attribute name="content">
            <xsl:text>English</xsl:text>
          </xsl:attribute>
        </meta>
        <meta>
          <xsl:attribute name="name">
            <xsl:text>DC.publisher</xsl:text>
          </xsl:attribute>
          <xsl:attribute name="content">
            <xsl:value-of select="NewsItem/Identification/NewsIdentifier/ProviderId"/>
          </xsl:attribute>
        </meta>
        <meta>
          <xsl:attribute name="name">
            <xsl:text>DC.rights</xsl:text>
          </xsl:attribute>
          <xsl:attribute name="content">
            <xsl:text>Copyright (C) </xsl:text>
            <xsl:value-of select="$avcomponent/RightsMetadata/Copyright/CopyrightHolder/Origin"/>
            <xsl:text> </xsl:text>
            <xsl:value-of select="$avcomponent/RightsMetadata/Copyright/CopyrightDate"/>
          </xsl:attribute>
        </meta>
        <meta>
          <xsl:attribute name="name">
            <xsl:text>DC.subject</xsl:text>
          </xsl:attribute>
          <xsl:attribute name="content">
            <xsl:value-of select="$textcomponent/NewsLines/KeywordLine"/>
          </xsl:attribute>
        </meta>
	<meta>
	  <xsl:attribute name="name">
	    <xsl:text>ABC.storyid</xsl:text>
	  </xsl:attribute>
	  <xsl:attribute name="content">
	    <xsl:value-of select="NewsItem/Identification/NewsIdentifier/NewsItemId"/>
	  </xsl:attribute>
	</meta>
        <meta>
          <xsl:attribute name="name">
            <xsl:text>ABC.type</xsl:text>
          </xsl:attribute>
          <xsl:attribute name="content">
            <xsl:value-of select="NewsEnvelope/NewsProduct/@FormalName"/>
          </xsl:attribute>
        </meta>
        <!-- ABC metadata -->
        <xsl:apply-templates select="NewsItem/NewsComponent[@Duid='wrapper']/DescriptiveMetadata/SubjectCode/Subject"/>
        <!-- description -->
        <desc>
	  <xsl:value-of select="$avcomponent/NewsLines/NewsLine/NewsLineText"/>
        </desc>
      </a>
    </cmml>
  </xsl:template>


  <xsl:template match="Subject">
    <meta>
      <xsl:attribute name="name">
        <xsl:value-of select="@Scheme"/>
      </xsl:attribute>
        <xsl:attribute name="content">
          <xsl:value-of select="@FormalName"/>
        </xsl:attribute>
      </meta>
  </xsl:template>


  <!--
  <xsl:template match="DataContent">
    <xsl:if test="NewsLines/HeadLine">
      <a>
	<xsl:attribute name="id"><xsl:value-of select="position()"/></xsl:attribute>
        <desc>
          <xsl:value-of select="NewsLines/HeadLine"/>
          <xsl:if test="NewsLines/NewsLine/NewsLineText">
	    <xsl:text>: </xsl:text>
            <xsl:for-each select="NewsLines/NewsLine/NewsLineText">
	      <xsl:value-of select="."/>
	    </xsl:for-each>
	  </xsl:if>
        </desc>
      </a>
    </xsl:if>
  </xsl:template>
-->

</xsl:stylesheet>
