Copied to clipboard

Flag this post as spam?

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


  • David 28 posts 156 karma points
    Nov 19, 2014 @ 10:27
    David
    0

    XSLT displays picture ID instead of the picture.

    Hello Umbraco Community,

    I've writen a XSLT to display all my single News Items.
    After that i inserted it to my template.

    This XSLT should display the single Items like that:

    -Header
    -Date
    -Picture

    My problem is that the picture displays the id instead of the picture.
    How can I fix this?

    I am using Umbraco 7.1.8

    This is my 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:Examine="urn:Examine" 
        exclude-result-prefixes="msxml umbraco.library Examine ">
    
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    
    <xsl:param name="currentPage"/>
    
    <xsl:template match="/">
    
    <!-- The fun starts here -->
    <ul>
    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
        <a>
            <h2><a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
                </a></h2>
              <small class="meta">Posted: <xsl:value-of select="umbraco.library:LongDate(@updateDate, true(), ' - ')"/></small><br/>
              <p class="introduction">
                <xsl:value-of select="umbraco.library:ReplaceLineBreaks(introduction)"/>
              </p>
    
    
            <xsl:value-of select="newspicture"/>
    
        </a>
    </xsl:for-each>
    </ul>
    
    </xsl:template>
    
    </xsl:stylesheet>
    
    

     

    Thank you very much.

    Sincerely David :)

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 19, 2014 @ 10:31
    Jan Skovgaard
    1

    Hi David

    That's because you need to find the image based on the id. You can see how it's done using XSLT here http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia

    So where you in your code currently have <xsl:value-of select="newspicture"/>

    You need this

     <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/newspicture, 0)" />
    
     <xsl:if test="$media">
      <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>
    

    Hope this makes sense :)

    Cheers, Jan

  • Steve Morgan 1349 posts 4458 karma points c-trib
    Nov 19, 2014 @ 10:34
    Steve Morgan
    0

    Jan beat me to it! His post is clearer!

     

     

     

     

  • David 28 posts 156 karma points
    Nov 19, 2014 @ 10:54
    David
    0

    Hello Jan,

    thank you for your fast answer.
    I've just replaced

    <xsl:value-of select="newspicture"/>

    with

     <xsl:variablename="media"select="umbraco.library:GetMedia($currentPage/newspicture, 0)"/>

     
    <xsl:iftest="$media">
     
    <xsl:variablename="url"select="$media/umbracoFile"/>
       
    <xsl:variablename="width"select="$media/umbracoWidth"/>
         
    <xsl:variablename="height"select="$media/umbracoHeight"/>
       
    <imgsrc="{$url}"width="{$width}"height="{$height}"/>
     
    </xsl:if>

    and it show the following error.

    What is wrong now?
    I don't get it.

    Thank you in advance.

    Sincerely David :)

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 19, 2014 @ 10:56
    Jan Skovgaard
    0

    Hi David

    Seems like your <xsl:if test> is wrong...it's collapsed into <xsl:iftest>

    /Jan

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 19, 2014 @ 11:02
    Dennis Aaen
    100

    Hi David,

    What if you do something like this:

     <xsl:if test="./newspicture !=''">
        <xsl:variable name="media" select="umbraco.library:GetMedia(./newspicture, 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>

    Hope this helps,

    /Dennis

  • David 28 posts 156 karma points
    Nov 19, 2014 @ 11:05
    David
    0

    Thank you very much, Dennis !
    This worked for me !!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 19, 2014 @ 11:07
    Jan Skovgaard
    0

    Ah yes, the classical test to see if we get an id at all :)

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft