Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jason Denousse 16 posts 46 karma points
    Mar 30, 2015 @ 16:43
    Jason Denousse
    0

    Dynamic Parameters in XSLT

    I have installed the insertFlash package into my Umbraco, however, when I select the macro for my template, I am asked to select the file. I want the flash file to be a dynamic choice from the Content section.

    Inserting my macro into a template looks like this :

    <umbraco:Macro mediaFile="1620" flashWidth="1024" flashHeight="768" Alias="InsertFlash" runat="server"></umbraco:Macro>

    I tried adding an Umbraco page field as a value for mediaFile like this <umbraco:Macro mediaFile="1620" flashWidth="1024" flashHeight="768" Alias="InsertFlash" runat="server"></umbraco:Macro>

    But that didnt work.

    I think I will have to edit the XSLT file, but not sure what to change. my XSLT file looks like this:

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>

    <xsl:stylesheet 

    version="1.0" 

    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 

            xmlns:msxml="urn:schemas-microsoft-com:xslt"

            xmlns:randomTools="http://www.umbraco.org/randomTools"

    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" 

    exclude-result-prefixes="msxml randomTools umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

     

    <xsl:output method="xml" omit-xml-declaration="yes"/>

     

    <xsl:template match="/">

     

      <xsl:variable name="mediaFile" select="/macro/mediaFile/*"/>

      <xsl:variable name="fileURL" select="/macro/fileURL"/>

      <xsl:variable name="width" select="/macro/flashWidth"/>

      <xsl:variable name="height" select="/macro/flashHeight"/>

      <xsl:variable name="cssId" select="/macro/cssId"/>

      <xsl:variable name="urlParameters" select="/macro/urlParameters"/>

     

      <xsl:if test="$mediaFile != '' or $fileURL != ''">

        <xsl:variable name="trueFileURL">

          <xsl:choose>

          <xsl:when test="$mediaFile != ''"><xsl:value-of select="$mediaFile/data[@alias = 'umbracoFile'] | $mediaFile/umbracoFile"/></xsl:when>

          <xsl:otherwise><xsl:value-of select="$fileURL"/></xsl:otherwise>

          </xsl:choose>

        </xsl:variable>

     

        <xsl:variable name="finalFileURL">

          <xsl:choose>

          <xsl:when test="$urlParameters != ''"><xsl:value-of select="concat($trueFileURL, $urlParameters)"/></xsl:when>

          <xsl:otherwise><xsl:value-of select="$trueFileURL"/></xsl:otherwise>

          </xsl:choose>

        </xsl:variable>

     

        <xsl:variable name="finalCssId">

          <xsl:choose>

          <xsl:when test="string($cssId) != ''"><xsl:value-of select="$cssId"/></xsl:when>

          <xsl:otherwise><xsl:value-of select="concat( 'ts-', randomTools:GetRandom() )"/></xsl:otherwise>

          </xsl:choose>

        </xsl:variable>

     

        <xsl:call-template name="insertFlash">

          <xsl:with-param name="finalFileURL" select="$finalFileURL"></xsl:with-param>

          <xsl:with-param name="width" select="$width"></xsl:with-param>

          <xsl:with-param name="height" select="$height"></xsl:with-param>

          <xsl:with-param name="finalCssId" select="$finalCssId"></xsl:with-param>

        </xsl:call-template>

     

      </xsl:if>

     

    </xsl:template>

     

    <xsl:template name="insertFlash">

      <xsl:param name="finalFileURL"/>

      <xsl:param name="width"/>

      <xsl:param name="height"/>

      <xsl:param name="finalCssId"/>

     

      <div id="{$finalCssId}">

        <xsl:text> </xsl:text>

      </div>

     

      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js">

        <xsl:text> </xsl:text>

      </script>

     

      <script type="text/javascript">

        <![CDATA[

        var flashvars = {};

        var params = {};

        var attributes = {};

     

        var path = "]]><xsl:value-of select="$finalFileURL" /><![CDATA[";

        var cssId = "]]><xsl:value-of select="$finalCssId" /><![CDATA[";

        var width = "]]><xsl:value-of select="$width" /><![CDATA[";

        var height = "]]><xsl:value-of select="$height" /><![CDATA[";

     

        swfobject.embedSWF( path, cssId, width, height, "9.0.0", false, flashvars, params, attributes);

        ]]>

      </script>

     

    </xsl:template>

     

     <msxml:script language="c#" implements-prefix="randomTools">

        <msxml:assembly href="../bin/umbraco.dll"/>

        <![CDATA[

            //Basic idea from http://our.umbraco.org/wiki/reference/xslt/snippets/getting-a-series-of-unique-random-numbers

     

            /// <summary>

            /// Gets a random integer that falls between the specified limits

            /// </summary>

            /// <returns>A random integer within the specified range</returns>

            public static int GetRandom() {

                Random r = umbraco.library.GetRandom();

                int returnedNumber = 0;

                lock (r)

                {

                    returnedNumber = r.Next();

                }

                return returnedNumber;

            }

        ]]>

      </msxml:script>

     

    </xsl:stylesheet>

     

    Can anybody please help?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 30, 2015 @ 16:54
    Jan Skovgaard
    0

    Hi Jason

    What version of Umbraco are you currently using? In the "Developer" setting you can find the macro and make it possible to insert it into a rich text editor so you can insert the flash files from within the content section. There is a "Insert macro" option in the rich text editor field. When doing this you'll be able to fill in the different parameters in a dialogue window.

    I hope this makes sense.

    May I ask why you need flash btw? I'm just wondering if there is a better way of doing what you need to achieve :)

    /Jan

  • Jason Denousse 16 posts 46 karma points
    Mar 30, 2015 @ 17:03
    Jason Denousse
    0

    Hi Jan

    I am using version v6.0.6. I will try what you have asked.

    The purpose for using flash is that I'm using Umbraco as a CMS for client who has an interactive kiosk. They create animated attract screens usually in flash, and these attract screens will be updated quite frequently. I give my client only access to the Content and Media section of Umbraco.

    The macro works, but I can only select the flash file once inserting the macro, I am aiming to make this dynamic from the Content section.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 30, 2015 @ 17:06
    Jan Skovgaard
    0

    Hi Jason

    Ok, but then you should be able to make it work like I described above :)

    Looking forward to hear if you succeed - Otherwise please let me know and I'll help you even further.

    /Jan

  • Jason Denousse 16 posts 46 karma points
    Mar 30, 2015 @ 17:20
    Jason Denousse
    0

    Thanks Jan that worked, not the way I imagined it to work, but it will do the job.

    Thanks for your help.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 30, 2015 @ 17:21
    Jan Skovgaard
    100

    Hi Jason

    You're welcome - How did you imagine it would work? Remember to mark the issue as solved btw so others who come across it can jump straight to the solution if they come across the same issue.

    /Jan

  • Jason Denousse 16 posts 46 karma points
    Mar 30, 2015 @ 17:30
    Jason Denousse
    0

    I added a richtext editor property to the template, and selected the macro from the content section, rather than from the templates section. This actually works out better as the customer can upload a different file type, add text and images etc so I am happy with that.

Please Sign in or register to post replies

Write your reply to:

Draft