Copied to clipboard

Flag this post as spam?

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


  • Klaus 47 posts 67 karma points
    Aug 14, 2011 @ 20:29
    Klaus
    0

    Associate images from subnodes on page

    The code below shows subnodes images on the page. However, it breaks whenever i dont associate an image with a subnode.

    I think i need an if statement, but i dont know how to dot it.


    Please advise me.

     

    <xsl:param name="currentPage"/>
    <xsl:variable name="field" select="/macro/field" />
        
    <xsl:template match="/">
            <xsl:apply-templates select="$currentPage/mediaItem[normalize-space()]" />
    </xsl:template>

    <xsl:template match="mediaItem">


    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
    <xsl:variable name="mediaNode" select="umbraco.library:GetMedia(., false())" />

              <li>
                <a href="{umbraco.library:NiceUrl(@id)}">
                  <div id="centerimg">
                    <xsl:if test="$mediaNode/umbracoFile">
                      <img class="latest_img" border="none" src="{$mediaNode/umbracoFile}" alt="{@nodeName}" width="200" height="160"/>
                    </xsl:if>
                  </div>
                </a>
              </li>


    </xsl:for-each>
    </xsl:template>

    Best regards

    Klaus

  • Fuji Kusaka 2203 posts 4220 karma points
    Aug 14, 2011 @ 21:14
    Fuji Kusaka
    0

    Hi Klaus,

    Are you trying to get the image from the media section or by associating the image to the page node by using media picker?

    If you are using the medie picker to choose an image from the media section you could try this

    <xsl:variable name="mediaFolder" select="$currentPage"/>
      <li>
                <href="{umbraco.library:NiceUrl(@id)}">
                  <div id="centerimg">
                   
    <xsl:if test="YourUploadAlias != ''"> 

    <img src="{umbraco.library:GetMedia(YourUploadAlias, 'true')/umbracoFile}"/>

    </xsl:if>
    </div>       
    </a>          
    </li>
  • Klaus 47 posts 67 karma points
    Aug 14, 2011 @ 21:18
    Klaus
    0

    Thank you so much - it worked perfectly.

  • Klaus 47 posts 67 karma points
    Aug 14, 2011 @ 23:34
    Klaus
    0

    Acutally, it worked for a second and then it broke. Could you please explain again. I rewrote according to your reply.

    <?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:issuu="urn:issuu"
      exclude-result-prefixes="msxml  umbraco.library  Exslt.ExsltCommon Exslt.ExsltDatesAndTimes  Exslt.ExsltMath  Exslt.ExsltRegularExpressions Exslt.ExsltStrings  Exslt.ExsltSets issuu ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

        
            <xsl:template match="/">
                    <xsl:apply-templates select="$currentPage/mediaItem[normalize-space()]" />
            </xsl:template>
            
            <xsl:template match="mediaItem">
              <xsl:variable name="mediaFolder" select="$currentPage"/>  <li>
                <href="{umbraco.library:NiceUrl(@id)}">
              <xsl:if test="mediaItem!= ''"
            <img src="{umbraco.library:GetMedia(mediaItem, 'true')/umbracoFile}"/>
          </xsl:if>
        </a>          
      </li>
    </xsl:template>
    </xsl:stylesheet>

  • Fuji Kusaka 2203 posts 4220 karma points
    Aug 15, 2011 @ 04:12
    Fuji Kusaka
    0

    Hi Klaus what do you mean by it broke?...the image was displayed and then disappeared? Can you try to

    <xsl:template match="/">

    <!-- The fun starts here -->
    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
      
    <li> 
    <xsl:if test="mediaItem!= ''">
              <xsl:element name="a">
                <xsl:attribute name="href">
                  <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
                </xsl:attribute>        <img src="{umbraco.library:GetMedia(mediaItem, 'true')/umbracoFile}"/>
              </xsl:element>
           </xsl:if>
    </li>
    </xsl:for-each>

     


  • Klaus 47 posts 67 karma points
    Aug 15, 2011 @ 09:15
    Klaus
    0

    Fantastic, that worked very well... What is the difference between the two snippets you gave?

    /Klaus

  • Fuji Kusaka 2203 posts 4220 karma points
    Aug 15, 2011 @ 09:35
    Fuji Kusaka
    0

    Great if its working.... Well the only difference is I made the checked for the media in theitself. So whenever it contains a media it will also add the link instead of having the link present all the time.

    Remember to mark this thread as solved for others who might need.

    //fuji

Please Sign in or register to post replies

Write your reply to:

Draft