Copied to clipboard

Flag this post as spam?

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


  • Bob McLane 19 posts 39 karma points
    Dec 01, 2010 @ 16:55
    Bob McLane
    0

    XSLT for placing an image on a page

    Hi I'm brand new to Umbraco and hope someone can help me out.

    Here's what I'm trying to do.....

    I've setup a document type called 'DefaultHome'. I've added a number of properties one of which is a Media Picker named home_imgLeft. My intent is that an editor can use the media picker property to select an image from the media library.

    I've setup a template that has an image tag. The document type above uses this this template. I'm having problems getting the value of the home_imgLeft to translate into a URL. Currently nothing comes back using the macro. If I just insert the umbraco field into the template I get back '1066'.

    I've looked around on the forum and found some XSLT examples but am still having problems, hope someone can tell me what I'm doing wrong.

    Template code ......

    <%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
    <umbraco:Macro Alias="BobImageTest3" runat="server"></umbraco:Macro> </asp:Content>

     

    XSLT code ......

     <?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="/">
    <xsl:if test="string($currentPage/data [@alias='home_imgLeft']) != '' ">
    <xsl:element name="img">
    <xsl:attribute name="src">
    <xsl:value-of select="umbraco.library:GetMedia($currentPage/data[@alias='home_imgLeft'], 'false')/data [@alias = 'umbracoFile']"/>
    </xsl:attribute>
    </xsl:element>
    </xsl:if>

    </xsl:template>
    </xsl:stylesheet>
  • Sebastian Dammark 583 posts 1407 karma points
    Dec 01, 2010 @ 17:06
    Sebastian Dammark
    0

    Hi Bob

    First of all you gotta use this package, XMLDump, since it'll save you a lot of time.

    When using XMLDump you can get a preview of the XML like this.
    http://dammark.dk.nt12.unoeuro.com/xmldump.aspx?media=1106

    This is a website I'm building for my self.

    Now you can try to show us the XML output of 'umbraco.library:GetMedia($currentPage/data[@alias='home_imgLeft'], 'false')' ...

     

     

     

  • Bob McLane 19 posts 39 karma points
    Dec 01, 2010 @ 17:27
    Bob McLane
    0

    Ok I think I'm XMLDump correctly in this case. Here's what I get back when I put in my URL .....

    http://192.168.200.201/xmldump.aspx?media=1066

    - <media>
      <Image id="1066" level="2" nodeName="people" urlName="people" nodeTypeAlias="Image" />
      </media>

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 01, 2010 @ 17:39
    Kim Andersen
    0

    Bob, which version of Umbraco are you using? Just need to know if you are using the new or the old XML schema.

    If you are using the "new" XML schema (default since v4.5.1 (in v4.5 there was a small bug)) this code should be working for you:

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

    But yeah, like Sebastian says, it's a good idea to see what XML the GetMedia-extension returns.

    /Kim A

  • Bob McLane 19 posts 39 karma points
    Dec 01, 2010 @ 17:42
    Bob McLane
    0

    Kim A, thanks. I'm using umbraco v4.5.2

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 01, 2010 @ 17:45
    Kim Andersen
    0

    Ahh didn't see your second reply before I posted my answer (I had opened this post as well as others in several tabs, and took some time before I got to this one :) ).

    But did it work for you, or do you stille have the problem?

    /Kim A

  • Bob McLane 19 posts 39 karma points
    Dec 01, 2010 @ 17:48
    Bob McLane
    0

    That fixed my problem! Thanks so much for the help!

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 01, 2010 @ 21:39
    Kim Andersen
    0

    Great to hear Bob!

    Remember to mark one of the answers as the solution :)

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft