Copied to clipboard

Flag this post as spam?

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


  • John Halsey 59 posts 220 karma points
    May 19, 2014 @ 11:18
    John Halsey
    0

    XSLT Code suddenly stopped working!

    Hello,

    I had a XSLT script that was listing out some images on a page, that was working perfectly, and has suddenly stopped this morning or over the weekend.

    The content editor did add some more images to the list but has done everything correctly.

    Is there a problem that I don't know about, or is there a problem in this code below?

    The folder that holds all the images in the content section has Id 1074.

    <ul>
        <xsl:for-each select="umbraco.library:GetXmlNodeById(1074)/BannerImage [@isDoc]">
            <xsl:choose>
                <xsl:when test="url != ''">
                    <xsl:variable name="mediaImage" select="umbraco.library:GetMedia(bannerImage, false())" />
                    <!-- check to see if the new browser check box was ticked -->
                    <xsl:variable name="window">
                        <xsl:choose>
                            <xsl:when test="not(linkTarget = '')">
                                _blank
                            </xsl:when>
                            <xsl:otherwise>
    
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:variable>
                    <li>
                        <a href="{umbraco.library:NiceUrl(url)}">
                            <xsl:attribute name="target">
                                <xsl:value-of select="$window"/>
                            </xsl:attribute>
                            <img src="{$mediaImage/umbracoFile}" alt="{$mediaImage/altText}" width="960" height="260" />
                        </a>
                    </li>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:variable name="mediaImage" select="umbraco.library:GetMedia(bannerImage, false())" />
                    <li>
                        <img src="{$mediaImage/umbracoFile}" alt="{$mediaImage/altText}" width="960" height="260" />
                    </li>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
    </ul>
    

    I have also written this out in Razor to see if that worked but no luck.

    @
        var banner = @Library.NodeById(1074);
        if(banner.Children.Any()){
    
        <ul>
         @foreach(var page in banner.Children){
            <li>
                @if(page.url != "")
                {
                    var target = "_self";
                    if(page.linkTarget)
                    {
                        target = "_blank";
                    }
                    <a href="@page.url" target="@target">
                        <img src="@page.Media("bannerImage","umbracoFile")" alt="@page.Media("bannerImage","altText")" width="960" height="260" />  
                    </a>
                }
                else
                {
                    <img src="@page.Media("bannerImage","umbracoFile")" alt="@page.Media("bannerImage","altText")" width="960" height="260" />      
                }
            </li> 
         }                 
        </ul>             
    
    }
    

    Can anyone advise what's going on? As I say, it did work perfectly, for about 2 months.

    Thanks John

  • Christian Liebe-Harkort 56 posts 104 karma points
    May 19, 2014 @ 11:37
    Christian Liebe-Harkort
    0

    Hi John, 

    Code looks good to me, what kind of output / error do you get now? 

    I would try unpublishing the newly added nodes, to identify the one that makes problems. 

    Maybe a corrupt image or problems with xml cache? 

    Christian

  • John Halsey 59 posts 220 karma points
    May 19, 2014 @ 11:50
    John Halsey
    0

    Hi Christian,

    I'm getting this error on the site "Error parsing XSLT file: \xslt\Banner.xslt".

    I'll check each image.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 19, 2014 @ 12:00
    Jan Skovgaard
    100

    Hi John

    What version of Umbraco are you using? If it's older than v6 then you can add ?umdebugshowtrace=1 to your page url to see if it reveals some more information about the error.

    If it's v6+ then go to /app_data/logs and search for "ERROR" and see if it reveals anything.

    However I think the issue probably is a missing id or an image node that has no image mapped to it.

    Just my 2 cents.

    /Jan

  • John Halsey 59 posts 220 karma points
    May 19, 2014 @ 12:05
    John Halsey
    0

    Its OK, I figured it out.

    The user had published a node that had no image on it, so the script didn't know what to do. Partly my fault I guess.

    It works now after I unpublished it.

    Thanks for the suggestions.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 19, 2014 @ 12:52
    Jan Skovgaard
    0

    Hi John

    I would probably also spend some time refactoring the above XSLT code...however a minor suggestion that is easy to quickly implement to avoid this from happening again would be to define your

    mediaImage variable right after the for-each loop so you define it here

    <xsl:for-each select="umbraco.library:GetXmlNodeById(1074)/BannerImage [@isDoc]">
       <xsl:variable name="mediaImage" select="umbraco.library:GetMedia(bannerImage, false())" />
    
       <!-- Make sure the $mediaImage variable is not empty -->
       <xsl:if test="normalize-space($mediaImage)">
    
        <!-- Place your when test here -->
    
       </xsl:if>
    </xsl:for-each>
    

    In the above example you eliminate that the error is occuring since it will never move into the if statement if $mediaImage is empty.

    Hope this helps and that it makes sense.

    Cheers, Jan

  • John Halsey 59 posts 220 karma points
    May 19, 2014 @ 12:55
    John Halsey
    0

    Hi Jan,

    Yes I already added an if statement this morning to stop this problem.

    Thanks John

Please Sign in or register to post replies

Write your reply to:

Draft