Copied to clipboard

Flag this post as spam?

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


  • Kevon K. Hayes 255 posts 281 karma points
    Aug 19, 2010 @ 17:46
    Kevon K. Hayes
    0

    Very New to XSLT and need to out the URL of an Image using the Media Picker

    Currently the Media Picker outputs the id of the image.

    From this page: http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia

    it states I'm suppose to use this format for version 4.5 and higher:

    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/imageAlias, 0)" />

    <img src="{$media/Image/umbracoFile}" alt="{$media/Image/altText}" />

    could someone tell me in NEWBIE terms what exactly am I supposed to do to return the URL... would help alot and springboard me on my XSLT endeavors... Thanks!

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 19, 2010 @ 17:51
    Lee Kelleher
    0

    Hey Kevon,

    Are you using v4.5.0 or v4.5.1?  (There was a minor bug in v4.5.0 with GetMedia).

    Hopefully you are using v4.5.1, if so, then you were so close!

    <img src="{$media/umbracoFile}" alt="{$media/altText}" />

    Just needed to remove the 'Image' bit (that was the bug in v4.5.0)

    Cheers, Lee.

  • Kevon K. Hayes 255 posts 281 karma points
    Aug 19, 2010 @ 17:54
    Kevon K. Hayes
    0

    4.5.1

    I understand $media is a variable that gets it's value from the first element... so would this be correct:

     <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/myIMAGE, 0)" />
     <img src="{$media/umbracoFile}" alt="{$media/altText}" />  ?

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 19, 2010 @ 18:05
    Lee Kelleher
    0

    Yes, it looks correct to me.  Give it a go, see what happens! :-)

  • Kevon K. Hayes 255 posts 281 karma points
    Aug 19, 2010 @ 18:26
    Kevon K. Hayes
    0

    Well doing it this way

     <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/corDepartmentImage, 0)">
                  <img src="{$media/umbracoFile}" alt="{$media/altText}" />
     </xsl:variable>

    I get the following output:

    and doing it this way:

    <div id="corDepartmentSummarySection" class="corDepartmentSummarySection">            
                  <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/corDepartmentImage, 0)" />
                  <img src="{$media/umbracoFile}" alt="{$media/altText}" />           
                  <umbraco:Item field="corDepartmentSummarySection" runat="server"></umbraco:Item>
    </div>

    I get the following output:

    ignore the font differences.  I'm using the alias of the media picker below in bold:

    $currentPage/corDepartmentImage, 0)
  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 19, 2010 @ 18:33
    Lee Kelleher
    0

    Hi Kevon,

    Where have you placed this code? in an XSLT or (Master) Template?

    You can't use .NET controls (like <umbraco:Item>) in XSLT and vice-versa, XSLT tags in Templates (i.e. <xsl:variable>)

    Let me know what you are using so far, then I can suggest a way to help.

    Thanks, Lee.

  • Kevon K. Hayes 255 posts 281 karma points
    Aug 19, 2010 @ 19:04
    Kevon K. Hayes
    0

    I inserted this directly into MasterPage.  Please advise procedure.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Aug 19, 2010 @ 19:20
    Kim Andersen
    1

    Hi there Kevon

    The XSLT that you have provided above looks right:

    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/corDepartmentImage, 0)" />
    <img src="{$media/umbracoFile}" alt="{$media/altText}" />

    But to make it work, you have to place this code inside of a XSLT-file, and then place a macro containing the XSLT inside of your masterpage. You can do like this:

    1. Go to the developer section in Umbraco and right-click the XSLT-folder. Here you'll choose to create a new XSLT.

    2. Name the XSLT, and make sure that there's a checkmark in the "Create macro"-checkbox. Just choose a Clean XSLT-file.

    3. Now you have created a new XSLT-file and a macro containing the file. In the XSLT-file you'll paste in the above code.

    4. Now you'll go to the settings section of Umbraco, and insert the new macro in your masterpage.

    5. You'll do this by clicking the small icon in the top called "Insert macro" - Choose the new macro you just created.

    6. Save the masterpage and you should be done.

    I hope the above mini guide makes sense and works for you :)

    /Kim A

  • Kevon K. Hayes 255 posts 281 karma points
    Aug 19, 2010 @ 19:32
    Kevon K. Hayes
    0

    Problem:  I inserted the bold XSLT below in the Clean XSLT Template:

    <?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: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 umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


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

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

        <!-- start writing XSLT -->
    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/corDepartmentImage, 0)" />
    <img src="{$media/umbracoFile}" alt="{$media/altText}" /> 
             

    </xsl:template>

    </xsl:stylesheet>

    Upon save I got the following error:

    Error occured

    System.OverflowException: Value was either too large or too small for an Int32.
    at System.Convert.ToInt32(Double value)
    at System.Double.System.IConvertible.ToInt32(IFormatProvider provider)
    at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType)
    at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

  • Kim Andersen 1447 posts 2196 karma points MVP
    Aug 19, 2010 @ 19:42
    Kim Andersen
    0

    Try changing the two lines to this:

    <xsl:if test="$currentPage/corDepartmentImage !=''">
    <xsl:variable
    name="media" select="umbraco.library:GetMedia($currentPage/corDepartmentImage, 0)" />
    <img src="{$media/umbracoFile}" alt="{$media/altText}" />
    </xsl:if>

    This will make sure that there's actually choosen an image in the picker. Otherwise no image will be rendered in the HTML.

    /Kim A

  • Kevon K. Hayes 255 posts 281 karma points
    Aug 19, 2010 @ 19:52
    Kevon K. Hayes
    0

    Like Ambien, it worked like a dream.

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft