Copied to clipboard

Flag this post as spam?

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


  • MartinB 411 posts 512 karma points
    Jun 11, 2011 @ 23:13
    MartinB
    0

    Xslt returns first child nodes image 3 times

    Hi there

    This structure:

    Homepage
      - Highlights
        - One
        - Two
        - Three

    Only returns the image from "One", but three times with this xslt. I'm going nuts here, i think i've read every post in here and fumbled around with xpath, which clearly is my problem as i can get the first image to output 3 times.

    What is missing since i dont get the images from Two and Three?

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


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

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <xsl:variable name="highlightID" select="1116" />
    <xsl:variable name="maxItems" select="3" />
    <xsl:variable name="mediaId" select="number($currentPage//highlightImage)" />



    <textarea>
    <xsl:copy-of select="$mediaId"/>
    </textarea>

    <!-- The fun starts here -->
    <xsl:for-each select="umbraco.library:GetXmlNodeById($highlightID)/* [@isDoc and string(umbracoNaviHide) != '1']">
    <xsl:if test="$maxItems &lt;= 3">
    <div class="hightlight">
    <h4><xsl:value-of select="highlightHeader"/></h4>

    <xsl:if test="$mediaId > 0">
    <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
    <xsl:if test="$mediaNode/umbracoFile">
    <img src="{$mediaNode/umbracoFile}" height="{$mediaNode/umbracoHeight}" width="{$mediaNode/umbracoWidth}" />
    </xsl:if>
    </xsl:if>

    <a href="{umbraco.library:NiceUrl(@id)}" class="highlightLink">
    <xsl:value-of select="highlightLinkText"/>
    </a>
    </div>
    </xsl:if>

    </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jun 11, 2011 @ 23:49
    Chriztian Steinmeier
    1

    Hi Martin,

    You're using the same mediaId for all the childpages (you're setting it as a top-level variable) - try this instead:

    <xsl:template match="/">
        <xsl:variable name="highlightID" select="1116" />
        <xsl:variable name="maxItems" select="3" />
    
        <xsl:for-each select="umbraco.library:GetXmlNodeById($highlightID)/*[@isDoc][not(umbracoNaviHide = 1)]">
            <xsl:if test="position() &lt;= $maxItems">
                <div class="hightlight">
                    <h4><xsl:value-of select="highlightHeader"/></h4>
    
                    <xsl:if test="normalize-space(highlightImage)"><!-- Check if an image was picked -->
                        <xsl:variable name="mediaNode" select="umbraco.library:GetMedia(highlightImage, 0)" />
                        <xsl:if test="$mediaNode/umbracoFile">
                            <img src="{$mediaNode/umbracoFile}" height="{$mediaNode/umbracoHeight}" width="{$mediaNode/umbracoWidth}" />                                    
                        </xsl:if>
                    </xsl:if>
    
                    <a href="{umbraco.library:NiceUrl(@id)}" class="highlightLink">
                        <xsl:value-of select="highlightLinkText"/>
                    </a>
                </div>  
            </xsl:if>
        </xsl:for-each>
    </xsl:template>

    /Chriztian

  • MartinB 411 posts 512 karma points
    Jun 12, 2011 @ 00:03
    MartinB
    0

    If i hadn't already made a hole in my door 3 hours ago i would have done so now. Jeeeeeez!!

    I thought that the mediaID got different through the loops and couldn't understand why my textareas kept showing the same id lol.

    Chriztian you're a true lifesaver and i'm such a dork! Gah....

     

Please Sign in or register to post replies

Write your reply to:

Draft