Copied to clipboard

Flag this post as spam?

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


  • Daniel Horn 319 posts 344 karma points
    Nov 11, 2010 @ 15:59
    Daniel Horn
    0

    Display image via xslt Umbraco 4.5.2

    <?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="/">
    <img>
    <xsl:attribute name="src">/umbraco/imageGen.ashx?image=/<xsl:value-of select="test"/>&amp;width=89&amp;height=147</xsl:attribute>
    <xsl:attribute name="alt">0</xsl:attribute>
    </img>

    </xsl:template>

    </xsl:stylesheet

     

    Instead of outputting the image it just outputs the hardcoded html:

    <img alt="0" src="/umbraco/imageGen.ashx?image=/&amp;width=89&amp;height=147">

     

    How do i get this to work?

  • Thor Madsen-Holm 82 posts 212 karma points c-trib
    Nov 11, 2010 @ 21:56
    Thor Madsen-Holm
    2

     

    Hey Daniel,

     

    In order to access the data fra a page you need to use the param <xsl:param name="currentPage"/>. In your example it would look something like this:

     

    <img>

        <xsl:attribute name="src">

            /umbraco/imageGen.ashx?image=/<xsl:value-of select="$currentPage/test"/>&amp;width=89&amp;height=147

        </xsl:attribute>

        <xsl:attribute name="alt">0</xsl:attribute>

    </img>

     

    However this would not display your image either, this would only output the id of the image.

    In order to get the url of your image, you need to use this extension: umbraco.library:GetMedia

     

    Try using this example:

     

    <xsl:variable name="image" select="umbraco.library:GetMedia($currentPage/test,'false')/umbracoFile" />

     

    <img>

        <xsl:attribute name="src">

            /umbraco/imageGen.ashx?image=/<xsl:value-of select="$image"/>&amp;width=89&amp;height=147

        </xsl:attribute>

        <xsl:attribute name="alt">0</xsl:attribute>

    </img>

     

    First i save the image url in a variable called "image". Then i use this variable to when generating the image "src".

     

    /Thor

     

  • Daniel Horn 319 posts 344 karma points
    Nov 11, 2010 @ 21:58
    Daniel Horn
    0

    Thanks Thor, I made something similar now, had to make macro recursive also so found a nice post (old) post by Neehouse..

     

    Is it best practice to make variables or is it just preference ? :)

  • Thor Madsen-Holm 82 posts 212 karma points c-trib
    Nov 11, 2010 @ 21:59
    Thor Madsen-Holm
    0

    I'm not sure if it's best practice, but i find them nice to use :-)

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 11, 2010 @ 22:07
    Jan Skovgaard
    2

    Hi Daniel

    I consider making variables best practice. It saves some calls, which is good for performance.

    /Jan

  • Daniel Horn 319 posts 344 karma points
    Nov 11, 2010 @ 22:11
    Daniel Horn
    0

    Thanks guys :)

Please Sign in or register to post replies

Write your reply to:

Draft