Copied to clipboard

Flag this post as spam?

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


  • sdfsfm 70 posts 94 karma points
    Aug 04, 2010 @ 17:56
    sdfsfm
    0

    Displaying image in xslt not working

    Hi I'm following the GetMedia reference to display an image in xslt but I'm getting an 'Error parsing XSLT file: \xslt\Products.xslt'on my page. I can't see where I'm going wrong

     

    <!-- Input the documenttype you want here -->
    <xsl:variable name="documentTypeAlias" select="string('Product')"/>
    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul class="all-products">

    <xsl:for-each select="$currentPage/* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']">
      <li>
    <
    a href="{umbraco.library:NiceUrl(@id)}" >

    <!-- snippet from umbraco reference -->
    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/productThumbnail, 0)" />
     <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}" width="{$width}" height="{$height}" />
     </xsl:if>

        </a>
    <h2>
    <a href="{umbraco.library:NiceUrl(@id)}" ><xsl:value-of select="@nodeName"/>
    </a>
    </
    h2>
    <p><xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(./productDescription), 100,'...')"  /></p>
     
    <p><a href="{umbraco.library:NiceUrl(@id)}" title="" class="btn btnGreen">View product</a></p>
    </li>
     </xsl:for-each>
    </ul>
    </xsl:template>

    I'm using the 4.5.1. Any ideas?

  • sdfsfm 70 posts 94 karma points
    Aug 04, 2010 @ 17:58
    sdfsfm
    0

    I forgot to mention productThumbnail is the alias for the media picker, and the images are if a folder within the media picker if that makes any difference.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Aug 04, 2010 @ 18:13
    Kim Andersen
    0

    Try this one out:

    <xsl:if test="$currentPage/productThumbnail!=''">
    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/productThumbnail, 0)" />
            <xsl:variable name="url" select="$media/umbracoFile" />
            <xsl:variable name="width" select="$media/umbracoWidth" />
            <xsl:variable name="height" select="$media/umbracoHeight" />
            <img src="{$url}" width="{$width}" height="{$height}" />
     </xsl:if>

    The code that you had before tried to use the GetMedia-extension even if there where no image selected. This causes an error if no image is selected in one of the mediapickers. Other than that, you where using some parts of the old XML scheme in your $url, $width and $height.

    Does the above code work?

    /Kim A

  • Sascha Wolter 615 posts 1101 karma points
    Aug 04, 2010 @ 18:16
    Sascha Wolter
    0

    Hi Ivor,

    you definitely don't need the @alias part anymore in 4.5+ and you would need to get the image by appending /Image, please see here at the bottom.

    Hope that helps,
    Sascha

  • Kim Andersen 1447 posts 2196 karma points MVP
    Aug 04, 2010 @ 18:17
    Kim Andersen
    0

    Actually you might want to put the first:

    <a href="{umbraco.library:NiceUrl(@id)}" >
    ...
    </a>

    inside of the <xsl:if> as well, to make sure there's not rendered an empty a-tag if no image is selected in the media picker.

    /Kim A

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

    @Sascha:

    In v.4.5.1 there is no more need of the /Image as far as I'm concerned :)

    /Kim A

  • Sascha Wolter 615 posts 1101 karma points
    Aug 04, 2010 @ 18:33
    Sascha Wolter
    0

    Oh, that's much better, didn't know that. :)

  • sdfsfm 70 posts 94 karma points
    Aug 04, 2010 @ 18:42
    sdfsfm
    0

    @Kim Thanks for the snippet I'm not getting the same error,However its not showing the image or the link now though

    my codes looks like this now:

    <ul class="all-products">

    <xsl:for-each select="$currentPage/* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']">
      <li>
        
    <xsl:if test="$currentPage/productThumbnail !=''">
      <a href="{umbraco.library:NiceUrl(@id)}" >
            <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/productThumbnail, 0)" />
            <xsl:variable name="url" select="$media/umbracoFile" />
            <xsl:variable name="width" select="$media/umbracoWidth" />
            <xsl:variable name="height" select="$media/umbracoHeight" />
            <img src="{$url}" width="{$width}" height="{$height}" />
        </a>
     </xsl:if>
     
    <h2><a href="{umbraco.library:NiceUrl(@id)}" ><xsl:value-of select="@nodeName"/></a></h2>
        <p><xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(./productDescription), 100,'...')"  /></p>
       <!--<xsl:value-of

    select="umbraco.library:TruncateString(umbraco.library:StripHtml(./data[@alias
    = 'productDesc']), 100,'...')"/>-->


    <p><a href="{umbraco.library:NiceUrl(@id)}" title="" class="btn btnGreen">View product</a></p>
    </li>
     </xsl:for-each>
    </ul>
  • Kim Andersen 1447 posts 2196 karma points MVP
    Aug 04, 2010 @ 18:52
    Kim Andersen
    0

    Hmm...well does the current page have a mediaPicker called productThumbnail or is it the child-nodes that the images shall be shown from?

    In that case you need to change it to:

    <xsl:if test="./productThumbnail !=''">
      <a href="{umbraco.library:NiceUrl(@id)}" >
            <xsl:variable name="media" select="umbraco.library:GetMedia(./productThumbnail, 0)" />
            <xsl:variable name="url" select="$media/umbracoFile" />
            <xsl:variable name="width" select="$media/umbracoWidth" />
            <xsl:variable name="height" select="$media/umbracoHeight" />
            <img src="{$url}" width="{$width}" height="{$height}" />
        </a>
     </xsl:if>

    /Kim A

  • sdfsfm 70 posts 94 karma points
    Aug 04, 2010 @ 18:55
    sdfsfm
    0

    Cool that worked, the child-nodes have the mediaPicker on it.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies