Sign up here and you can log into the forum!

XSL Support for templates

Support forum for the great ThumbGen software

XSL Support for templates   

Postby thumbgen » Sun Apr 11, 2010 6:12 am

Starting with v0.12.12 (beta) I implemented a basic support for XSL 1.0 (XSL 2.0 is (and will) NOT be supported). Here's how it works:

Currently we have a template.xml that is loaded by TG then filled with infos and then rendered using the rendering engine.

Optionally it is possible now to place a template.xslt file near the template.xml. This will change the processing flow as following:

Template.xml (with tokens)-> TG fills the tokens -> if template.xslt exists -> TG applies the XSL to the filled-up xml -> render the result

Author of the template/XSL must be very careful with the result of his transformation as that one is sent to the rendering engine. I recommend doing an identity copy and then processing individual cases.
I also recommend checking log.txt when something goes wrong as most of the errors are logged there.

The XSL transformation is optional and may help defining conditions and other tasks right before rendering.

Here is a sample of an XSL file (it is complete, you can use it as start point):
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
   <xsl:template match="@*|node()">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
   </xsl:template>
   <xsl:template match="//Elements">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
         <xsl:choose>
            <xsl:when test="//tokens/token[@name='%SUBTITLES4%'] = '' ">
               <TextElement Name="Sub4Missing" X="150" Y="100" Width="1076" Height="51" AutoSize="False" Multiline="False" Font="Arial Narrow,22,True,False,False,False,Point,,0" ForeColor="-16728065" StrokeColor="-16777216" StrokeWidth="0" Text="Subtitle 4 is empty" TextAlignment="TopLeft" TextQuality="AntiAlias"/>
            </xsl:when>
         </xsl:choose>

         <TextElement Name="AddedViaTemplate" X="150" Y="0" Width="1076" Height="51" AutoSize="False" Multiline="False" Font="Arial Narrow,41,True,False,False,False,Point,,0" ForeColor="-16728065" StrokeColor="-16777216" StrokeWidth="0" Text="I AM A DYNAMIC ELEMENT" TextAlignment="TopLeft" TextQuality="AntiAlias"/>
      </xsl:copy>
   </xsl:template>
</xsl:stylesheet>


Basically the transformation copies the initial XML, then if the token named %SUBTITLES4% is empty adds a new TextElement and at the end add always a TextElement with some demo text inside.

The input XML processed by this transformation looks like: (the content was stripped out to show just interesting elements)
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<ImageDrawTemplate SDKVersion="2.0">
  <OutputImageSettings ColorDepth="Format32bppAlpha" ImageFormat="Jpeg" JpegCompressionLevel="80" Dpi="96" />
  <Canvas AutoSize="False" CenterElements="False" Height="720" Width="1280" Fill="Solid,16777215,-16777216,BackwardDiagonal,-1,-16777216,0,,Tile,None,50,100,,,,0,0,0,0,Line,True" />
  <Elements>
    <ImageElement Name="Background" X="0" Y="0" Width="1280" Height="720" Source="File" Offset="0" MultiPageIndex="-1" SourceData="C:\Documents and Settings\Radu\My Documents\Visual Studio 2008\Projects\ThumbGen(1)\bin\Debug\Templates\NeatSheet_AllBlack_1280x720\black.bmp" NullImageUrl="" />
    <ImageElement Name="S" X="237" Y="615" Width="50" Height="50" Source="File" Offset="0" MultiPageIndex="-1" SourceData="C:\Documents and Settings\Radu\My Documents\Visual Studio 2008\Projects\ThumbGen(1)\bin\Debug\Templates\NeatSheet_AllBlack_1280x720\s.png" NullImageUrl="" />
  </Elements>
  <tokens>
    <token name="%STUDIOS%">Barbarian Films</token>
    <token name="%EXTERNALSUBTITLESTEXT%">Espa&amp;#241;ol/Rom&amp;#226;na</token>
    <token name="%SUBTITLESTEXT%">Rom&amp;#226;na</token>
    <token name="%VIDEOFORMATTEXT%" />
    <token name="%AUDIOCHANNELSTEXT%">2</token>
    <token name="%EPISODE%" />
    <token name="%FRAMERATETEXT%">23.976</token>
    <token name="%CONTAINERTEXT%">Matroska</token>
    <token name="%AUDIOCODECTEXT%">MP3</token>
    <token name="%FANART1%">c:\temp\8e1324a0-e184-4848-b7b8-0915fb2d12e8.jpg</token>
    <token name="%PATH%">C:\Documents and Settings\Radu\My Documents\Visual Studio 2008\Projects\ThumbGen(1)\bin\Debug\Templates\NeatSheet_AllBlack_1280x720</token>
    <token name="%RUNTIME%">97</token>
    <token name="%COVER%">c:\temp\d5bba67f-eae3-4bfd-942c-80eb8ab38d37.jpg</token>
    <token name="%YEAR%">2009</token>
    <token name="%MEDIAFORMATTEXT%">MKV</token>
    <token name="%TITLE%">Spread</token>
    <token name="%RATING%">6.1/10</token>
    <token name="%SUBTITLES2%" />
    <token name="%EXTERNALSUBTITLES4%" />
    <token name="%EXTERNALSUBTITLES3%" />
    <token name="%DURATIONTEXT%">1h 36m</token>
    <token name="%VIDEORESOLUTIONTEXT%">768x576</token>
    <token name="%AUDIOBITRATETEXT%">128 Kbps</token>
    <token name="%TITLEPATH%">D:\Test\Spread</token>
    <token name="%DIRECTORS%">David Mackenzie</token>
    <token name="%SUBTITLES3%" />
    <token name="%SUBTITLES4%" />
    <token name="%EXTERNALSUBTITLES2%">Romanian</token>
    <token name="%ORIGINALTITLE%">Spread</token>
    <token name="%FANART2%">c:\temp\1339521c-cd5d-4ae4-b373-60c42eb870ff.jpg</token>
    <token name="%SUBTITLES5%" />
    <token name="%SOUNDFORMATTEXT%">All Mpeg</token>
    <token name="%PLOT%">A sex comedy centered on a serial womanizer and his jilted lover.</token>
    <token name="%COUNTRIES%">USA</token>
    <token name="%GENRES%">Comedy, Drama, Romance</token>
    <token name="%CERTIFICATION%">R</token>
    <token name="%SUBTITLES%">Romanian</token>
    <token name="%FILESIZETEXT%">781.95 MB</token>
    <token name="%BACKGROUND%">c:\temp\784256ad-7c68-4c4f-95fc-ff8e45629907.jpg</token>
    <token name="%MPAA%">Rated R for strong sexual content, nudity and language</token>
    <token name="%SUBTITLES1%">Romanian</token>
    <token name="%FRAMERATE%">23_976</token>
    <token name="%EXTERNALSUBTITLES1%">Spanish</token>
    <token name="%VIDEOCODECTEXT%">AVC</token>
    <token name="%CERTIFICATIONTEXT%">R</token>
    <token name="%ASPECTRATIO%">16-9</token>
    <token name="%ACTORS%">Ashton Kutcher, Anne Heche, Margarita Levieva, Sebastian Stan</token>
    <token name="%RELEASEDATE%">17.01.2009</token>
    <token name="%ASPECTRATIOTEXT%">16:9</token>
    <token name="%VIDEORESOLUTION%">768x576</token>
    <token name="%VIDEOBITRATETEXT%">977 Kbps</token>
    <token name="%RESOLUTIONTEXT%" />
    <token name="%EXTERNALSUBTITLES5%" />
    <token name="%SEASON%" />
    <token name="%FANART3%">c:\temp\0271d22d-d4f2-41b4-92bb-345daba0c679.jpg</token>
    <token name="%EXTERNALSUBTITLES%">Spanish/Romanian</token>
  </tokens>
</ImageDrawTemplate>



The XML sent to the rendering engine after applying the transformation can be seen in the new "Test template" dialog in ThumbGen and will look like (the content was stripped out to show just interesting elements):
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<ImageDrawTemplate SDKVersion="2.0">
   <OutputImageSettings ColorDepth="Format32bppAlpha" ImageFormat="Jpeg" JpegCompressionLevel="80" Dpi="96"/>
   <Canvas AutoSize="False" CenterElements="False" Height="720" Width="1280" Fill="Solid,16777215,-16777216,BackwardDiagonal,-1,-16777216,0,,Tile,None,50,100,,,,0,0,0,0,Line,True"/>
   <Elements>
      <ImageElement Name="Background" X="0" Y="0" Width="1280" Height="720" Source="File" Offset="0" MultiPageIndex="-1" SourceData="C:\Documents and Settings\Radu\My Documents\Visual Studio 2008\Projects\ThumbGen(1)\bin\Debug\Templates\NeatSheet_AllBlack_1280x720\black.bmp" NullImageUrl=""/>
      <ImageElement Name="S" X="237" Y="615" Width="50" Height="50" Source="File" Offset="0" MultiPageIndex="-1" SourceData="C:\Documents and Settings\Radu\My Documents\Visual Studio 2008\Projects\ThumbGen(1)\bin\Debug\Templates\NeatSheet_AllBlack_1280x720\s.png" NullImageUrl=""/>
      <TextElement Name="Sub4Missing" X="150" Y="100" Width="1076" Height="51" AutoSize="False" Multiline="False" Font="Arial Narrow,22,True,False,False,False,Point,,0" ForeColor="-16728065" StrokeColor="-16777216" StrokeWidth="0" Text="Subtitle 4 is empty" TextAlignment="TopLeft" TextQuality="AntiAlias"/>
      <TextElement Name="AddedViaTemplate" X="150" Y="0" Width="1076" Height="51" AutoSize="False" Multiline="False" Font="Arial Narrow,41,True,False,False,False,Point,,0" ForeColor="-16728065" StrokeColor="-16777216" StrokeWidth="0" Text="I AM A DYNAMIC ELEMENT" TextAlignment="TopLeft" TextQuality="AntiAlias"/>
   </Elements>
   <tokens>
      <token name="%STUDIOS%">Barbarian Films</token>
                    ............
   </tokens>
</ImageDrawTemplate>



In the near future I will add near the <tokens> node a new <mediainfo> node will COMPLETE data extracted from mediainfo. That way inside the XSL transformation you have access to all media flags as they are generated by mediainfo.
Last edited by thumbgen on Wed Apr 28, 2010 1:12 am, edited 2 times in total.
Get ThumbGen!
If you like ThumbGen then buy me a coffee Image
User avatar
thumbgen
Developer
 
Posts: 1094
Joined: Mon Apr 05, 2010 10:04 pm

Full mediainfo support   

Postby thumbgen » Sun Apr 11, 2010 7:53 am

Version v0.12.13beta available here: http://www.mediafire.com/?jmjid1kawwz adds full support for mediainfo.dll.

Under the <File> node you find the untouched information provided by MediaInfo.dll. I don't assume any responsability for what is inside the <File> node; it way vary between mediainfo releases if the mediainfo developer is not careful with backward compatibility

Code: Select all
<ImageDrawTemplate SDKVersion="2.0">
   <OutputImageSettings ColorDepth="Format32bppAlpha" ImageFormat="Png" JpegCompressionLevel="0" Dpi="96" />
   <Canvas AutoSize="False" CenterElements="False" Height="720" Width="1280" Fill="Solid,-16777216,-16777216,BackwardDiagonal,-1,-16777216,0,,Tile,None,50,100,,,,0,0,0,0,Line,True" />
   <Elements>
...................................
   </Elements>
   <tokens>
      <token name="%STUDIOS%">Barbarian Films</token>
      <token name="%EXTERNALSUBTITLESTEXT%">Espa&amp;#241;ol/Rom&amp;#226;na</token>
      <token name="%SUBTITLESTEXT%">Rom&amp;#226;na</token>
      <token name="%VIDEOFORMATTEXT%" />
      <token name="%AUDIOCHANNELSTEXT%">2</token>
      <token name="%EPISODE%" />
      <token name="%FRAMERATETEXT%">23.976</token>
      <token name="%CONTAINERTEXT%">Matroska</token>
      <token name="%AUDIOCODECTEXT%">MP3</token>
      <token name="%FANART1%">c:\temp\af51b55a-71d7-4df3-aa6b-2ae416d3f67f.jpg</token>
      <token name="%PATH%">c:\Program Files\Babel\BabelOut\Templates\WindeTiny</token>
      <token name="%RUNTIME%">97</token>
      <token name="%COVER%">c:\temp\b24bf8d4-7579-445f-b1c3-b1978d20630a.jpg</token>
      <token name="%YEAR%">2009</token>
      <token name="%MEDIAFORMATTEXT%" />
      <token name="%TITLE%">Spread</token>
      <token name="%RATING%">6.1/10</token>
      <token name="%SUBTITLES2%" />
      <token name="%EXTERNALSUBTITLES4%" />
      <token name="%EXTERNALSUBTITLES3%" />
      <token name="%DURATIONTEXT%">1h 36m</token>
      <token name="%VIDEORESOLUTIONTEXT%">768x576</token>
      <token name="%AUDIOBITRATETEXT%">128 Kbps</token>
      <token name="%TITLEPATH%">D:\Test\Spread</token>
      <token name="%DIRECTORS%">David Mackenzie</token>
      <token name="%SUBTITLES3%" />
      <token name="%SUBTITLES4%" />
      <token name="%EXTERNALSUBTITLES2%">Romanian</token>
      <token name="%ORIGINALTITLE%">Spread</token>
      <token name="%FANART2%">c:\temp\33bd378a-3505-4d55-a722-7473b5ecd206.jpg</token>
      <token name="%SUBTITLES5%" />
      <token name="%SOUNDFORMATTEXT%" />
      <token name="%PLOT%">A sex comedy centered on a serial womanizer and his jilted lover.</token>
      <token name="%COUNTRIES%">USA</token>
      <token name="%GENRES%">Comedy, Drama, Romance</token>
      <token name="%CERTIFICATION%">R</token>
      <token name="%SUBTITLES%">Romanian</token>
      <token name="%FILESIZETEXT%">781.95 MB</token>
      <token name="%BACKGROUND%">c:\temp\e6e966f4-cdf1-4ebd-8a4a-b42b2bd91c30.jpg</token>
      <token name="%MPAA%">Rated R for strong sexual content, nudity and language</token>
      <token name="%SUBTITLES1%">Romanian</token>
      <token name="%FRAMERATE%">23_976</token>
      <token name="%EXTERNALSUBTITLES1%">Spanish</token>
      <token name="%VIDEOCODECTEXT%">AVC</token>
      <token name="%CERTIFICATIONTEXT%">R</token>
      <token name="%ASPECTRATIO%">16-9</token>
      <token name="%ACTORS%">Ashton Kutcher
Anne Heche
Margarita Levieva</token>
      <token name="%RELEASEDATE%">17.01.2009</token>
      <token name="%ASPECTRATIOTEXT%">16:9</token>
      <token name="%VIDEORESOLUTION%">768x576</token>
      <token name="%VIDEOBITRATETEXT%">977 Kbps</token>
      <token name="%RESOLUTIONTEXT%" />
      <token name="%EXTERNALSUBTITLES5%" />
      <token name="%SEASON%" />
      <token name="%FANART3%">c:\temp\d89114df-bfe3-48ff-a1be-01aa9affc085.jpg</token>
      <token name="%EXTERNALSUBTITLES%">Spanish/Romanian</token>
   </tokens>
   <File>
      <track type="General">
         <Complete_name>D:\Test\Spread\Spread.mkv</Complete_name>
         <Format>Matroska</Format>
         <File_size>782 MiB</File_size>
         <Duration>1h 36mn</Duration>
         <Overall_bit_rate>1 128 Kbps</Overall_bit_rate>
         <Encoded_date>UTC 2009-11-26 05:33:59</Encoded_date>
         <Writing_application>mkvmerge v2.9.8 ('C'est le bon') built on Aug 13 2009 12:49:06</Writing_application>
         <Writing_library>libebml v0.7.7 + libmatroska v0.8.1</Writing_library>
      </track>
      <track type="Video">
         <ID>1</ID>
         <Format>AVC</Format>
         <Format_Info>Advanced Video Codec</Format_Info>
         <Format_profile>High@L3.1</Format_profile>
         <Format_settings__CABAC>Yes</Format_settings__CABAC>
         <Format_settings__ReFrames>2 frames</Format_settings__ReFrames>
         <Muxing_mode>Container profile=Unknown@3.1</Muxing_mode>
         <Codec_ID>V_MPEG4/ISO/AVC</Codec_ID>
         <Duration>1h 36mn</Duration>
         <Bit_rate>977 Kbps</Bit_rate>
         <Nominal_bit_rate>1 000 Kbps</Nominal_bit_rate>
         <Width>768 pixels</Width>
         <Height>576 pixels</Height>
         <Display_aspect_ratio>16:9</Display_aspect_ratio>
         <Frame_rate_mode>Variable</Frame_rate_mode>
         <Frame_rate>23.976 fps</Frame_rate>
         <Resolution>8 bits</Resolution>
         <Colorimetry>4:2:0</Colorimetry>
         <Scan_type>Progressive</Scan_type>
         <Bits__Pixel_Frame_>0.092</Bits__Pixel_Frame_>
         <Stream_size>678 MiB (87%)</Stream_size>
         <Writing_library>x264 core 78 r1309 4d77de8</Writing_library>
         <Encoding_settings>cabac=1 / ref=1 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=6 / psy=1 / psy_rd=1.0:0.0 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / chroma_qp_offset=-2 / threads=5 / nr=0 / decimate=1 / mbaff=0 / constrained_intra=0 / bframes=3 / b_pyramid=0 / b_adapt=1 / b_bias=0 / direct=3 / wpredb=1 / keyint=250 / keyint_min=25 / scenecut=40 / rc_lookahead=40 / rc=abr / mbtree=1 / bitrate=1000 / ratetol=1.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00</Encoding_settings>
      </track>
      <track type="Audio">
         <ID>2</ID>
         <Format>MPEG Audio</Format>
         <Format_version>Version 1</Format_version>
         <Format_profile>Layer 3</Format_profile>
         <Format_Settings_Mode>Joint stereo</Format_Settings_Mode>
         <Format_Settings_ModeExtension>MS Stereo</Format_Settings_ModeExtension>
         <Codec_ID>A_MPEG/L3</Codec_ID>
         <Codec_ID_Hint>MP3</Codec_ID_Hint>
         <Duration>1h 36mn</Duration>
         <Bit_rate_mode>Constant</Bit_rate_mode>
         <Bit_rate>128 Kbps</Bit_rate>
         <Channel_s_>2 channels</Channel_s_>
         <Sampling_rate>48.0 KHz</Sampling_rate>
         <Stream_size>88.8 MiB (11%)</Stream_size>
         <Writing_library>LAME3.98 </Writing_library>
         <Encoding_settings>-m j -V 4 -q 2 -lowpass 17 -b 128</Encoding_settings>
      </track>
      <track type="Text">
         <ID>3</ID>
         <Format>UTF-8</Format>
         <Codec_ID>S_TEXT/UTF8</Codec_ID>
         <Codec_ID_Info>UTF-8 Plain Text</Codec_ID_Info>
         <Language>Romanian</Language>
      </track>
   </File>
</ImageDrawTemplate>
Get ThumbGen!
If you like ThumbGen then buy me a coffee Image
User avatar
thumbgen
Developer
 
Posts: 1094
Joined: Mon Apr 05, 2010 10:04 pm

XSL to display OriginalTitle only if different than Title   

Postby thumbgen » Mon Apr 12, 2010 9:46 am

Another idea of usage of XSL is when you want to not show Original Title when it is the same as Title for example ;)

A sample XSL that does that is this one:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
   <xsl:template match="@*|node()">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
   </xsl:template>
   <xsl:template match="//Elements">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
   </xsl:template>
   <xsl:template match="TextElement[@Name='OriginalTitle']">
      <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'"/>
      <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
      <!-- store in the $originalTitleFinal variable the value of the %ORIGINALTITLE% (to be used later if we need the OriginalTitle element) -->
      <xsl:variable name="originalTitleFinal" select="//tokens/token[@name='%ORIGINALTITLE%']"/>
      <!-- store in the $originalTitle variable the value of the %ORIGINALTITLE% (uppercase always to make comparation more accurate) -->
      <xsl:variable name="originalTitle" select="translate(//tokens/token[@name='%ORIGINALTITLE%'], $smallcase, $uppercase)"/>
      <!-- store in the $title variable the value of the %TITLE% (uppercase always to make comparation more accurate) -->
      <xsl:variable name="title" select="translate(//tokens/token[@name='%TITLE%'], $smallcase, $uppercase)"/>
      <xsl:choose>
         <!-- when value of $originalTitle is not the same as $title it means the strings are different so it makes sense to display the OriginalTitle corresponding TextElement -->
         <xsl:when test="$originalTitle != $title ">
            <xsl:copy>
               <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
         </xsl:when>
      </xsl:choose>
   </xsl:template>
</xsl:stylesheet>


If you place the above Template.xslt near any (or all) of dribbler1's latest templates you'll get Original title displayed only if it is different than Title.
Last edited by thumbgen on Sat Apr 17, 2010 1:12 am, edited 1 time in total.
Get ThumbGen!
If you like ThumbGen then buy me a coffee Image
User avatar
thumbgen
Developer
 
Posts: 1094
Joined: Mon Apr 05, 2010 10:04 pm

XSL to show empty.png if the%SUBTITLES4% token is empty   

Postby thumbgen » Wed Apr 14, 2010 4:20 am

A sample XSL that displays an empty.png instead of a subtitle flag if the %SUBTITLES4% token is empty:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
   <!-- we must store as variable the value of the %PATH% token for later use-->
   <xsl:variable name="PathValue" select="//tokens/token[@name='%PATH%']"/>
   <xsl:template match="@*|node()">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
   </xsl:template>
   <xsl:template match="//Elements">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
         <xsl:choose>
         <!-- if the value of the %SUBTITLES4% token is empty-->
            <xsl:when test="//tokens/token[@name='%SUBTITLES4%'] = '' ">
            <!-- we create a new ImageElement to be displayed -->
               <ImageElement Name="Sub4Missing" X="195" Y="320" Width="36" Height="24" Source="File" Offset="0" MultiPageIndex="-1" NullImageUrl="" UseSourceDpi="False">
               <!-- we construct here the path to the SourceData by taking the value of $PathValue and adding rest of the path to the empty.png -->
               <!-- IMPORTANT: We NEVER uses tokens (like %PATH%) in the elements that we generate via XSL (the rendering engine doesn't know what to do with them)-->
               <!-- we must fill token value from //tokens/token[@name=%mytoken%]-->
                  <xsl:attribute name="SourceData"><xsl:value-of select="$PathValue"/>\Flags\empty.png</xsl:attribute>
               </ImageElement>
            </xsl:when>
         </xsl:choose>
      </xsl:copy>
   </xsl:template>
</xsl:stylesheet>
Get ThumbGen!
If you like ThumbGen then buy me a coffee Image
User avatar
thumbgen
Developer
 
Posts: 1094
Joined: Mon Apr 05, 2010 10:04 pm

XSL to show %STUDIOS% IF %STUDIOS%.png is missing.   

Postby Plasmator » Sat Apr 17, 2010 7:00 pm

Code: Select all
<?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:myjs="urn:custom-javascript"   
exclude-result-prefixes="msxsl myjs" >

   <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

   <xsl:variable name="PathValue" select="//tokens/token[@name='%PATH%']"/>
   <xsl:variable name="Common" select="string('\..\Common\studios\')"/>
   <xsl:variable name="Studios" select="//tokens/token[@name='%STUDIOS%']"/>
   <xsl:variable name="ImageExt" select="string('.png')"/>
   <xsl:variable name="StudioLogo" select="concat($PathValue,$Common,$Studios,$ImageExt)"/>

   <msxsl:script language="JavaScript" implements-prefix="myjs">

        function FileExist(oFileName){

           var oFile = new ActiveXObject("Scripting.FileSystemObject");

           if ( oFile.FileExists(oFileName) ) {
              return 'True';
           }else{
              return 'False';
           }
        };

   </msxsl:script>

   <xsl:template match="@*|node()">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
   </xsl:template>

   <xsl:template match="//Elements">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>

         <xsl:choose>
            <xsl:when test=" myjs:FileExist($StudioLogo) = 'False' ">

               <TextElement Name="Studios" X="50" Y="372" Width="230" Height="50" AutoSize="False" Multiline="True" Font="Arial,12,Point,,0" ForeColor="-2578" StrokeColor="-16777216" StrokeWidth="0" TextAlignment="MiddleCenter" TextQuality="AntiAlias" >
                  <xsl:attribute name="Text"><xsl:value-of select="$Studios"/></xsl:attribute>
               </TextElement>

            </xsl:when>
         </xsl:choose>

      </xsl:copy>
   </xsl:template>

</xsl:stylesheet>
Plasmator
WDTVer
 
Posts: 35
Joined: Fri Apr 09, 2010 10:32 am

Re: XSL Support for templates   

Postby thumbgen » Sun Apr 18, 2010 2:53 am

I knew it that the XSL support will be useful :D Very nice solution and many thanks for sharing it :ugeek:
Get ThumbGen!
If you like ThumbGen then buy me a coffee Image
User avatar
thumbgen
Developer
 
Posts: 1094
Joined: Mon Apr 05, 2010 10:04 pm

Formatting audio channels XSL   

Postby thumbgen » Mon Apr 26, 2010 8:57 am

A useful snippet about formatting the audiochannels in the "common" spoken language (eg. 6 channels = 5.1)

Code: Select all
<?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:myjs="urn:custom-javascript" exclude-result-prefixes="msxsl myjs">
   <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
   <!-- declare a function that receives the number of channels and returns the formatted values -->
   <msxsl:script language="JavaScript" implements-prefix="myjs">

        function GetFormattedChannels(channelsCount)
      {
         switch (channelsCount)
         {
            case '2':
               return '2.0';
            break;    
            case '3':
               return '2.1';
            break;    
            case '4':
               return '4.0';
            break;    
            case '5':
               return '4.1';
            break;    
            case '6':
               return '5.1';
            break;    
            case '7':
               return '6.1';
            break;    
            case '8':
               return '7.1';
            break;    
         }
         return 'none';
        };

   </msxsl:script>
   <!-- store the number of channels in the PathValue variable -->
   <xsl:variable name="PathValue" select="//tokens/token[@name='%AUDIOCHANNELSTEXT%']"/>
   <!-- copy all nodes from source XML to the final XML -->
   <xsl:template match="@*|node()">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
   </xsl:template>
   <!-- when we arrive at Elements node, we copy it and we add a new Chanels named node -->
   <xsl:template match="//Elements">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
         <!-- we call the js function passing the $PathValue to it; the result is the formatted number of channels -->
         <TextElement Name="Chanels" X="100" Y="100" Width="500" Height="30" AutoSize="False" Multiline="False" Font="Arial,20,True,False,False,False,Point,,0" ForeColor="-2578" StrokeColor="-16777216" StrokeWidth="0" TextAlignment="TopLeft" TextQuality="AntiAlias">
            <xsl:attribute name="Text"><xsl:value-of select="myjs:GetFormattedChannels(string($PathValue))"/>, </xsl:attribute>
         </TextElement>
      </xsl:copy>
   </xsl:template>
</xsl:stylesheet>

Get ThumbGen!
If you like ThumbGen then buy me a coffee Image
User avatar
thumbgen
Developer
 
Posts: 1094
Joined: Mon Apr 05, 2010 10:04 pm

Idea   

Postby thumbgen » Mon Apr 26, 2010 8:59 am

I suggest that the template makes that are developing using XSL should try to NOT use any TextElement/ImageElement inside the XSL... if we keep inside XSL only logic and the "look" stays inside the template.xml we can easily reuse transformations or make a HUGE XSL file that contains a lot of gimmicks.

One way would be to show/hide elements inside XSL based on conditions, declare areas in template.xml that are shown/hidden based on conditions, etc
Get ThumbGen!
If you like ThumbGen then buy me a coffee Image
User avatar
thumbgen
Developer
 
Posts: 1094
Joined: Mon Apr 05, 2010 10:04 pm

Re: XSL Support for templates   

Postby thumbgen » Mon Apr 26, 2010 1:12 pm

Get ThumbGen!
If you like ThumbGen then buy me a coffee Image
User avatar
thumbgen
Developer
 
Posts: 1094
Joined: Mon Apr 05, 2010 10:04 pm

Re: XSL Support for templates   

Postby Buhric » Mon Apr 26, 2010 5:47 pm

Ok, I need help on this...

I spend the last 3 hours trying to understan how xsl works.... but I cant figure it out...

Basicaly, what I want to do is format the text in a token that ThumbGen create.. namely %EPISODELIST%
I want to do this to it...
put the %EPISODE% nth item in bold. <-- don't know if even doable

But I'm not even able to replace the "Text" attribute of the TextElement that already exists
here's whatI have so far
Code: Select all
<?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:myjs="urn:custom-javascript" exclude-result-prefixes="msxsl myjs">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <!-- declare a function that receives the number of channels and returns the formatted values -->
  <msxsl:script language="JavaScript" implements-prefix="myjs">
    function GetFormattedList(list)
    {
      return "test";
    };
  </msxsl:script>
  <xsl:variable name="EpListNum" select="//tokens/token[@name='%EPISODELIST%']"/>
  <xsl:variable name="EpListName" select="//tokens/token[@name='%EPISODENAMESLIST%']"/>
  <!-- copy all nodes from source XML to the final XML -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
    <xsl:template match="//Elements">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
   
  <xsl:template match="TextElement[@Name='EpisodeListNumbers']">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
      <xsl:attribute name="Text">
        <xsl:value-of select="myjs:GetFormattedList(string($EpListNum))"/>,
      </xsl:attribute>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>
Buhric
Global Moderator
 
Posts: 616
Joined: Thu Apr 15, 2010 2:49 pm

Next

Return to ThumbGen

Who is online

Users browsing this forum: No registered users and 1 guest