﻿<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="urn:TridionComponentLink" xmlns:tqb="urn:TridionQueryBuilder">
  <xsl:output method="xml"  omit-xml-declaration="yes"/>
  <xsl:template match="Component">

    <PlayList  Id="{@Id}" Title="{@Title}">
      <xsl:copy-of select="Headline"/>
      <xsl:copy-of select="Abstract" />
      <xsl:copy-of select="Magazine"/>
      <xsl:copy-of select="Type"/>
      <Thumbnail Id="{Thumbnail/Component/@Id}" Title="{Thumbnail/Component/@Title}" src="{Thumbnail/Component/@src}" Display="{ThumbnailDisplay}">
        <xsl:copy-of select="Thumbnail/Component/*"/>
      </Thumbnail>
      <xsl:copy-of select="AutoRotate"/>
      <xsl:copy-of select="RotateFrequency"/>
      <xsl:copy-of select="DisplayCaptions"/>

      <Assets>
        <xsl:variable name="images" select="Assets/AssetLink" />
        <xsl:variable name="captions" select="Assets/Caption"/>
        <xsl:variable name="componentlinks" select="Assets/ComponentLink"/>
        <xsl:for-each select="$captions">
          <xsl:element name="AssetItem">
            <xsl:variable name="pos" select="position()"/>
            <xsl:choose>
              <xsl:when test="$images[$pos]/Component">
                <xsl:call-template name="DisplayMultimediaComponents">
                  <xsl:with-param name="currentNode" select="$images[$pos]/Component"/>
                </xsl:call-template>
                <xsl:copy-of select="$images[$pos]/Component/*"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:call-template name="DisplayComponentLinks">
                  <xsl:with-param name="currentNode" select="$componentlinks[$pos]/*"/>
                </xsl:call-template>
                <xsl:copy-of select="$componentlinks[$pos]/*"/>
              </xsl:otherwise>

            </xsl:choose>
            <xsl:element name="Caption">
              <xsl:copy-of select="node()"/>
            </xsl:element>
          </xsl:element>
        </xsl:for-each>
        <xsl:copy-of select="tqb:GetList(AutomatedSlideshowQuery)"/>
      </Assets>
      <xsl:copy-of select="View"/>
      <MetaData>
        <xsl:copy-of select="Metadata/*"/>
      </MetaData>
    </PlayList>

  </xsl:template>
  <xsl:template name="DisplayMultimediaComponents">
    <xsl:param name="currentNode"/>
    <xsl:attribute name="Id">
      <xsl:value-of select="$currentNode/@Id" />
    </xsl:attribute>
    <xsl:attribute name="Title">
      <xsl:value-of select="$currentNode/@Title" />
    </xsl:attribute>
    <xsl:attribute name="src">
      <xsl:value-of select="$currentNode/@src" />
    </xsl:attribute>
  </xsl:template>
  <xsl:template name="DisplayComponentLinks">
    <xsl:param name="currentNode"/>
    <xsl:attribute name="Id">
      <xsl:value-of select="$currentNode/@ComponentUri"  />
    </xsl:attribute>
    <xsl:attribute name="Title">
      <xsl:value-of select="$currentNode/text()" />
    </xsl:attribute>
    <xsl:attribute name="src">
      <xsl:if test="$currentNode/@ComponentUri!=''">
        $web<xsl:value-of select="tcl:GetLink($currentNode/@ComponentUri)"/>
      </xsl:if>
    </xsl:attribute>
  </xsl:template>

</xsl:stylesheet>

