Copied to clipboard

Flag this post as spam?

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


  • Eddie Foreman 215 posts 288 karma points
    Sep 23, 2010 @ 23:52
    Eddie Foreman
    0

    Get Media Item

    Hi All

    Trying to place an image on a page, using an xslt that I've used on other projects.  Currently using Umbraco 4.5.2, set to use the legacy schema.

        <xsl:template match="/">
        <xsl:variable name="mediaNode" select="number($currentPage/data [@alias = 'bannerImage'])" />
        <xsl:if test ="$mediaNode &gt; 0">
          <xsl:variable name="mediaItem" select="umbraco.library:GetMedia($mediaNode, 0)" />
          <xsl:if test="string($mediaItem/data [@alias = 'umbracoFile']) != ''">
            <img src="{$mediaItem/data[@alias='umbracoFile']}">
              <xsl:attribute name="alt">
                <xsl:choose>
                  <xsl:when test="string($mediaItem/data[@alias='alttext']) != '' ">
                    <xsl:value-of select="$mediaItem/data[@alias='alttext']" />
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="$mediaItem/@nodeName" />
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:attribute>
            </img>
          </xsl:if>
        </xsl:if>
      </xsl:template>

    If I place the following in the template, the media node id is displayed on the page.

    <xsl:value-of select="umbraco.library:GetMedia($currentPage/data[@alias='bannerImage'], 0)/data [@alias = 'umbracoFile']"/>

    Any ideas on how I can get the xslt to work?

    Thanks in advance

    Eddie

  • Eddie Foreman 215 posts 288 karma points
    Sep 24, 2010 @ 00:26
    Eddie Foreman
    0

    Hi All

    Got it working.

    Could someone, respond so I can close the ticket.

    Thanks

    Eddie

  • Kim Andersen 1447 posts 2196 karma points MVP
    Sep 25, 2010 @ 15:12
    Kim Andersen
    1

    Eddie, maybe you could post the answer in here, so that if someone else in the future run's into a similar problem, they can find the solution in this post :)

    /Kim A

  • Eddie Foreman 215 posts 288 karma points
    Sep 25, 2010 @ 15:51
    Eddie Foreman
    0

    Hi Kim

    The posted xslt was fine, it turned out to be a typo on a custom media type where umbracofile, should have been umbracoFile.

    Thanks for replying.

    Eddie

Please Sign in or register to post replies

Write your reply to:

Draft