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 @ 18:48
    Greyhound
    0

    Unable to get image height or width in Macro

    Hi,

    I have been working on a media picker for my home page. Basically I want to be able to pick an image and have the xslt retrieve the image data for rendering into HTML.

    I am using the Improved Media Picker and my code is as follows:

    Template:

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

    Thus far so good, my parameter gets passed through to the XSLT

    Most of my XSLT works ok, all of it that is apart from getting the umbracoWidth and umbracoHeight values which always seem to return empty strings. My XSLT code is as follows:

    <?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>

    I think I must be doing something fundamentally wrong here. Please could someone point me in the right direction.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 05, 2010 @ 20:48
    Dirk De Grave
    0

    I'm pretty sure this post is most related to your other post and resolved as such?

     

    Cheers,

    /Dirk

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jul 05, 2010 @ 20:52
    Kim Andersen
    0

    Hi there Greyhound

    Are your $url working as well?

    As far as I can see the $media contains a lillte to much. Maybe you can try this:

    <!-- start writing XSLT -->
    <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/data [@alias = 'umbracoWidth']"/>
    </xsl:if>

    In your $media you where including the filename of the file, so I'm pretty sure this is what's wrong. I haven't tested the above code though, but you could try giving it a shot :)

    /Kim A

  • Greyhound 102 posts 124 karma points
    Jul 06, 2010 @ 08:55
    Greyhound
    0

    Hi,

    Dirk De Grave - I somehow ended up with two posts. Once wasn't appearing for me so I posted again.

    Kim A - thank you for posting this it is indeed correct.

    Thanks for making this one of the best forums I have ever used.

Please Sign in or register to post replies

Write your reply to:

Draft