<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:myCPrefix="urn:custom-net"
xmlns:myJSPrefix="urn:custom-javascript" exclude-result-prefixes="msxsl myCPrefix myJSPrefix">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="folderflags" select="string('\..\Common\lstarflags\')"/>
<xsl:variable name="folderchannel" select="string('\..\Common\Channels\')"/>
<xsl:variable name="foldercodec" select="string('\..\Common\sound_format\')"/>
<xsl:variable name="folderprofile" select="string('\..\Common\sound_format\')"/>
<xsl:variable name="pathvalue" select="//tokens/token[@name='%PATH%']"/>
<xsl:variable name="imageext" select="string('.png')"/>
<xsl:variable name="audiolanguage1" select="//File/track[@type='Audio']/Language"/>
<xsl:variable name="audiolanguage2" select="//File/track[@type='Audio' and @streamid='2']/Language"/>
<xsl:variable name="audiolanguage3" select="//File/track[@type='Audio' and @streamid='3']/Language"/>
<xsl:variable name="profileaudio1" select="//File/track[@type='Audio']/Format_profile"/>
<xsl:variable name="profileaudio2" select="//File/track[@type='Audio' and @streamid='2']/Format_profile"/>
<xsl:variable name="audiocodec1" select="//File/track[@type='Audio']/Format"/>
<xsl:variable name="audiocodec2" select="//File/track[@type='Audio' and @streamid='2']/Format"/>
<xsl:variable name="audiochannels1" select="//File/track[@type='Audio']/Channel_s_"/>
<xsl:variable name="audiochannels2" select="//File/track[@type='Audio' and @streamid='2']/Channel_s_"/>
<xsl:variable name="flag1" select="concat($pathvalue,$folderflags,$audiolanguage1,$imageext)"/>
<xsl:variable name="flag2" select="concat($pathvalue,$folderflags,$audiolanguage2,$imageext)"/>
<xsl:variable name="flag3" select="concat($pathvalue,$folderflags,$audiolanguage3,$imageext)"/>
<xsl:variable name="codec1" select="concat($pathvalue,$foldercodec,$audiocodec1,$imageext)"/>
<xsl:variable name="codec2" select="concat($pathvalue,$foldercodec,$audiocodec2,$imageext)"/>
<xsl:variable name="codec3" select="concat($pathvalue,$foldercodec,'HR.png')"/>
<xsl:variable name="codec4" select="concat($pathvalue,$foldercodec,'MA.png')"/>
<xsl:variable name="Channel1" select="concat($pathvalue,$folderchannel,$audiochannels1,$imageext)"/>
<xsl:variable name="Channel2" select="concat($pathvalue,$folderchannel,$audiochannels2,$imageext)"/>
<xsl:variable name="STUDIOS" select="string(//tokens/token[@name='%STUDIOS%'])"/>
<xsl:variable name="PATH" select="string(//tokens/token[@name='%PATH%'])"/>
<xsl:variable name="rating" select="//tokens/token[@name='%RATING%']"/>
<msxsl:script implements-prefix="myJSPrefix" language="JavaScript">
<![CDATA[
function trim(oString)
{
return oString.replace(/^([\s\t\n]|\ \;)+|([\s\t\n]|\ \;)+$/g, '');
}
var Studios = []; //Stores the Studio Names
function findStudios(oStudios, oTemplatePath)
{
Studios = oStudios.split("," );
var oFile = new ActiveXObject("Scripting.FileSystemObject" );
var path='';
for(var i = 0; i < Studios.length; i++)
{
path = oTemplatePath + '\\..\\common\\studios\\' + trim(Studios[i]) + '.png';
if (oFile.FileExists(path))
{
return trim(Studios[i]);
}
}
return trim(Studios[0]);
}
]]>
</msxsl:script>
<msxsl:script implements-prefix="myCPrefix" language="CSharp">
<![CDATA[
public int CalculateRatingWidth(string rating, int totalWidth)
{
string[] _r = rating.Split('/');
if (_r.Length == 2)
{
double _rating = !string.IsNullOrEmpty(_r[0]) ? Convert.ToDouble(_r[0],System.Globalization.CultureInfo.InvariantCulture) : 1;
return (int)(totalWidth * _rating / 10);
}
return 1;
}
]]>
</msxsl:script>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:variable name="RatingWidth" select="//Elements/ImageElement[@Name='Bars']/@Width"/>
<xsl:variable name="CalculatedRatingWidth" select="myCPrefix:CalculateRatingWidth(string($rating), $RatingWidth)"/>
<xsl:template match="//Elements/ImageElement[@Name='Bars']/Actions/Crop/@Width">
<xsl:attribute name="Width"><xsl:value-of select="$CalculatedRatingWidth"/></xsl:attribute>
</xsl:template>
<xsl:template match="//ImageElement[@Name='Studio']/@SourceData">
<xsl:attribute name="SourceData">
<xsl:value-of select="concat($PATH,'\..\common\Studios\',string(myJSPrefix:findStudios($STUDIOS,$PATH)),'.png')"/>
</xsl:attribute>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ImageElement[@Name='Aud1']">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:choose>
<xsl:when test="$audiolanguage1 != '' ">
<xsl:attribute name="SourceData"><xsl:value-of select="$flag1"/></xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="ImageElement[@Name='Aud2']">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:choose>
<xsl:when test="$audiolanguage2 != '' ">
<xsl:attribute name="SourceData"><xsl:value-of select="$flag2"/></xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="ImageElement[@Name='Aud3']">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:choose>
<xsl:when test="$audiolanguage3 != '' ">
<xsl:attribute name="SourceData"><xsl:value-of select="$flag3"/></xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ImageElement[@Name='Codecaudio1']">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:choose>
<xsl:when test ="$profileaudio1 !='HRA_/_Core'">
<xsl:attribute name="SourceData"><xsl:value-of select="$codec3"/></xsl:attribute>
</xsl:when>
<xsl:when test ="$profileaudio1 != 'MA_/_Core' ">
<xsl:attribute name="SourceData"><xsl:value-of select="$codec4"/></xsl:attribute>
</xsl:when>
<xsl:otherwise >
<xsl:attribute name="SourceData"><xsl:value-of select="$codec1"/></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ImageElement[@Name='Codecaudio2']">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:choose>
<xsl:when test="$audiocodec2 != 'HRA_/_Core' ">
<xsl:attribute name="SourceData"><xsl:value-of select="$codec3"/></xsl:attribute>
</xsl:when>
<xsl:when test="$audiocodec2 != 'MA_/_Core' ">
<xsl:attribute name="SourceData"><xsl:value-of select="$codec4"/></xsl:attribute>
</xsl:when>
<xsl:when test="$audiocodec2 != '' ">
<xsl:attribute name="SourceData"><xsl:value-of select="$codec1"/></xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="ImageElement[@Name='chan1']">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:choose>
<xsl:when test="$audiochannels1 != '' ">
<xsl:attribute name="SourceData"><xsl:value-of select="$Channel1"/></xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="ImageElement[@Name='chan2']">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:choose>
<xsl:when test="$audiochannels2 != '' ">
<xsl:attribute name="SourceData"><xsl:value-of select="$Channel2"/></xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>