Copied to clipboard

Flag this post as spam?

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


  • pna 11 posts 31 karma points
    Nov 10, 2012 @ 17:29
    pna
    0

    Xslt loop

    I want to reteive all images from the subpages to the current  page (where i amn executing the script) and need a little push to get the  looping right.... 

    This is my code

     

    <!-- The fun starts here -->

     

    <div class=List">

    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">

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

     

      <xsl:variable name="mediaId" select="number($currentPage/node()/billede)" />

        <xsl:if test="$mediaId > 0">

            <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />

            <xsl:if test="$mediaNode/umbracoFile">

     <img src="{$mediaNode/umbracoFile}" alt="[image]" height="{umbracoHeight}" width="{umbracoWidth}" />

            </xsl:if>

          </a>

    </h3>

    =====================

     

    The image I want is stored in a Mediapicker namned = "billede"

     

     

    This gives me an indentical list  with the images stored in the mediapicker on the first subpage/node + a link to the subpage 

    What I want I is a list of all images found on subpages + the link to the subpage where  image is located.

    A piece of cake I suppose  but it seems that I canĀ“t  cut it right now. 

    Any hints appreciated !

    /Poul

    (umbraco v 4.9.0 (Assembly version: 1.0.4633.18696))

     

     

     

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 10, 2012 @ 18:37
    Dennis Aaen
    0

    Hi Poul,

    I will try to help you, if I can.

    I have take a look on your XSLT code and the only line that I can see a possible mistake, is the line below.

    <xsl:variable name="mediaId" select="number($currentPage/node()/billede)" />

    It seems that you have mixed the new and the old XML schema.

    <!-- The fun starts here -->

    <div class=List">

    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">

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

        
        <xsl:variable name="mediaId" select="number($currentPage/billede)" />

        <xsl:if test="$mediaId > 0">

            <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />

            <xsl:if test="$mediaNode/umbracoFile">

         <img src="{$mediaNode/umbracoFile}" alt="[image]" height="{umbracoHeight}" width="{umbracoWidth}" />

            </xsl:if>

          </a>

    </h3>

    Try this, and see if it solve your problem. I hope so.

    /Dennis

  • pna 11 posts 31 karma points
    Nov 10, 2012 @ 19:43
    pna
    0

    Hi Dennis

    Thx for the answer .... Unfortunately it does not seem to work -  no image is returned. I still  suspect my missing looping skils   to cause the problem.

    :-) Poul 

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 10, 2012 @ 19:54
    Dennis Aaen
    0

    Okay Poul.

    Perhaps the problem could be that you have umbracoFile,
    Maybe try this one and see that it works. I have not tested myself.

     

    <xsl:iftest="$mediaId > 0">

           
    <xsl:variablename="mediaNode"select="umbraco.library:GetMedia($mediaId, 0/umbracoFile)"/>

           
    <xsl:iftest="$mediaNode!=''">

         
    <imgsrc="{$mediaNode}"alt="[image]"height="{umbracoHeight}"width="{umbracoWidth}"/>

     
    </xsl:if>

    I will try to help the best I can.

    /Dennis

  • pna 11 posts 31 karma points
    Nov 10, 2012 @ 20:49
    pna
    0

    Nope: that  change threw  multiple red lines when I tried to save the file

    System.Xml.Xsl.XslLoadException: Expression must evaluate to a node-set. 
    ...raco.library:GetMedia($mediaId, -->0<-- /umbracoFile) An error occurred at d:\web\localuser\levendelandsby.dk\public_html\xslt\634881771518785310_temp.xslt(29,9). 
    at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) 
    at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) 
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

     

    ...when i tried with ................. <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId,0)" />

    I still get a repeating image....!

    /Poul

     

     

     

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Nov 11, 2012 @ 00:37
    Chriztian Steinmeier
    0

    Hi Poul,

    Here's a fixed version of your original code (I've tried to highlight the important changes):

    <xsl:for-each select="$currentPage/*[@isDoc][not(umbracoNaviHide = 1)]">
        <h3 class="headline">
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:if test="normalize-space(billede)">
                    <xsl:variable name="mediaNode" select="umbraco.library:GetMedia(billede, 0)" />
                    <xsl:if test="$mediaNode/umbracoFile">
                        <img src="{$mediaNode/umbracoFile}" alt="[image]" height="{$mediaNode/umbracoHeight}" width="{$mediaNode/umbracoWidth}" />
                    </xsl:if>
                </xsl:if>
            </a>
        </h3>
    </xsl:for-each>
    
    When you're inside a for-each, XPath expressions are relative to the context node, so "billede" will refer to the subpage currently processed (your original used $currentPage everytime).

    /Chriztian

  • pna 11 posts 31 karma points
    Nov 11, 2012 @ 00:56
    pna
    0

    Hi Chriztian - thx a lot.


    I  will need to explore  thar one. The fixed code does exacltly what  I want it to do.

    I  was not aware of "normalize-space"  -  quite usefull I can see.  

    :-)))  Poul

     

Please Sign in or register to post replies

Write your reply to:

Draft