Copied to clipboard

Flag this post as spam?

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


  • Greyhound 102 posts 124 karma points
    Jul 05, 2010 @ 19:02
    Greyhound
    0

    Media picker - xslt

    Hi,

    I have a media picker (am using the improved media picker) and I want to be able to select an image and have this displayed on the page.

    All is well up to a point. I can pass the mediaID through to the XSLT, find the media item and return the URL.

    The problem occurs when I want to get umbracoHeight and umbracoWidth - these always return an empty string. I'm hoping someone may be able to help me with this or offer some advice if I am getting this fundamentally wrong.

    Code in template:
    <umbraco:Macro mediaID="[#FooterLogos]" Alias="GetFooterImageFile" runat="server"></umbraco:Macro>

    Code in XSLT:
    <?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" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary" exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary ">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="mediaID" select="macro/mediaID" />
    <xsl:template match="/">

       
       
    <!-- start writing XSLT -->
    <xsl:variable name="media" select="umbraco.library:GetMedia($mediaID, 0)/data [@alias = 'umbracoFile']" />
    <xsl:if test="($media) != ''">
    <xsl:variable name="url" select="$media [@alias = 'umbracoFile']" />
    <xsl:variable name="width" select="$media [@alias = 'umbracoWidth']" />
    <xsl:variable name="height" select="$media [@alias = 'umbracoHeight']" />
    <img src="{$url}" />
    <xsl:value-of select="$media [@alias = 'umbracoWidth']"/>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>

    Thanks in advance

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jul 05, 2010 @ 19:07
    Sebastiaan Janssen
    0

    You should probably change it to something this: 

    <xsl:variable name="media" select="umbraco.library:GetMedia($mediaID, 0)" />
    <xsl:if test="($media) != ''">
    <xsl:variable name="url" select="$media/data [@alias = 'umbracoFile']" />
    <xsl:variable name="width" select="$media/data [@alias = 'umbracoWidth']" />
    <xsl:variable name="height" select="$media/data [@alias = 'umbracoHeight']" />
    <img src="{$url}" />
    <xsl:value-of select="$media [@alias = 'umbracoWidth']"/>
    </xsl:if>

    Also check out Lee Kelleher's excellent blogpost about media items in xslt.

  • Greyhound 102 posts 124 karma points
    Jul 05, 2010 @ 19:17
    Greyhound
    0

    Thanks for posting.

    Using

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

    returns an empty string which is why I had to use my original code.
    I did look through Lee's post but cannot get it to work and am unable to find any complete examples of what I wish to receive - I'm lost with this.

     

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jul 05, 2010 @ 19:20
    Sebastiaan Janssen
    0

    Ah, I see, my bad, try this one:

    <xsl:variable name="media" select="umbraco.library:GetMedia($mediaID, 0)" />
            <xsl:if test="count($media/data) &gt; 0 and string($media/data[@alias='umbracoFile']) != ''">
                    <xsl:variable name="url" select="$media/data [@alias = 'umbracoFile']" />
                    <xsl:variable name="width" select="$media/data [@alias = 'umbracoWidth']" />
                    <xsl:variable name="height" select="$media/data [@alias = 'umbracoHeight']" />
                    <img src="{$url}" />
                <xsl:value-of select="$media [@alias = 'umbracoWidth']"/>
        </xsl:if>
  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jul 05, 2010 @ 19:21
    Sebastiaan Janssen
    0

    Ehm, or rather this one:

    <xsl:variable name="media" select="umbraco.library:GetMedia($mediaID, 0)" />
            <xsl:if test="count($media/data) &gt; 0 and string($media/data[@alias='umbracoFile']) != ''">
                    <xsl:variable name="url" select="$media/data [@alias = 'umbracoFile']" />
                    <xsl:variable name="width" select="$media/data [@alias = 'umbracoWidth']" />
                    <xsl:variable name="height" select="$media/data [@alias = 'umbracoHeight']" />
                    <img src="{$url}" />
                    <xsl:value-of select="$media/data [@alias = 'umbracoWidth']"/>
            </xsl:if>
  • Greyhound 102 posts 124 karma points
    Jul 05, 2010 @ 19:50
    Greyhound
    0

    Aha! - I see my folly.

    That works (and makes sense too) - thank you kindly for your valuable time.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jul 05, 2010 @ 19:54
    Sebastiaan Janssen
    0

    No problem! We've all been there staring ourselves blind on something. ;)

Please Sign in or register to post replies

Write your reply to:

Draft