Copied to clipboard

Flag this post as spam?

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


  • Sam 184 posts 209 karma points
    Dec 04, 2010 @ 13:02
    Sam
    0

    Render a list image otherwise rollback image

    Hi everyone, I know my xslt is pretty lame still but I am trying!


    <!-- Renders the list containing the Documents -->
    <xsl:template name="RenderNodes">
    <xsl:param name="documents" />
    <xsl:param name="page" />
    <xsl:param name="numDisplay" />

    <xsl:variable name="startPosition" select="($page * $numDisplay - $numDisplay) + 1" />
    <xsl:variable name="endPosition" select="$page * $numDisplay" />
    <div id="list-wrapper">
    <ul class="list">
    <xsl:for-each select="$documents">
    <xsl:sort select="./@createDate" order="descending" />
    <li>



    <xsl:choose>
    <xsl:when test="position() &gt;= $startPosition and position() &lt;= $endPosition">
    <xsl:variable name="focusImage" select="./data [@alias = 'PreviewImage1']"/>
    <xsl:if test="string($focusImage) != ''">
    <xsl:variable name="mediaId" select="$focusImage" />
    <xsl:if test="$mediaId &gt; 0">
    <xsl:variable name="media" select="umbraco.library:GetMedia($mediaId, false)" />
    <a href="{umbraco.library:NiceUrl(./@id)}"><img alt="{$media/@nodeName}" src="{$media/data [@alias = 'umbracoFile']}" width="250" /></a>
    </xsl:if>
    </xsl:if>
    <p><a href="{umbraco.library:NiceUrl(./@id)}"><xsl:value-of select="@nodeName"/></a></p>
    </xsl:when>
    <xsl:otherwise>-----ROLLBACK IMAGE IN HERE-----</xsl:otherwise>
    </xsl:choose>



    </li>
    </xsl:for-each>
    </ul>
    </div>


    </xsl:template>

    I am trying to insert a rollback image in this list if there is no image present in the content section (I select an image via the media picker).

    I have tried all sorts of combos but I really need some proper help from someone who understands what each bit of the code does. I have so far worked out that moving the variables outside of the <xsl:choose> does not render the list properly, and theat <xsl:when> cannot be a child of <xsl:when> etc etc..anyway, that's propbably very basic to you guys. I have adapted this from the runway news xslt so credit to Kim Løwert :)

    Thanks if anyone can shed some light on this. I just don't know in which order to put this stuff. I imagine it's all over the place! On a plus note, it works perfectly when useing <xsl:if> statements rather than choose, whens and otherwise...

    Perhaps there is a better way? Or maybe I'm on the right track, not sure :(

    Regards,

    Sam.

  • Rich Green 2246 posts 4008 karma points
    Dec 04, 2010 @ 13:13
    Rich Green
    0

    Hey Sam,

    Does the above code all work when you have an image?

    If so then you just need to add a choose statement to show when there is no image

    <xsl:choose>
    <xsl:when test="$mediaId &gt; 0">
            <xsl:variable name="media" select="umbraco.library:GetMedia($mediaId, false)" />
                    <a href="{umbraco.library:NiceUrl(./@id)}"><img alt="{$media/@nodeName}" src="{$media/data [@alias = 'umbracoFile']}" width="250" /></a>
    
    </xsl:when>
    <xsl:otherwise>
          <!--Show default image here--> 
    </xsl:otherwise>
    </xsl:choose>

    paste this in to replace 

     <xsl:if test="$mediaId &gt; 0">
                    <xsl:variable name="media" select="umbraco.library:GetMedia($mediaId, false)" />
                        <a href="{umbraco.library:NiceUrl(./@id)}"><img alt="{$media/@nodeName}" src="{$media/data [@alias = 'umbracoFile']}" width="250" /></a>
                  </xsl:if>

    Your code could be cleaned up a bit as you don't need to assign the media variable twice (once to focusImage and then again to mediaid)

    Your logic is a little out of place for when the image is blank, got to run, if I get more time I'll post a further explantion.

    hth

    Rich

  • Sam 184 posts 209 karma points
    Dec 04, 2010 @ 13:16
    Sam
    0

    Thanks Rich,

    Yeah works ok with an image (picked in the content area), then just displays nothing when no image present.

    I'm just not sure how to clean it up, will persevere and post back :)

    Sam.

  • Sam 184 posts 209 karma points
    Dec 04, 2010 @ 13:29
    Sam
    0

    This works perfectly :) not sure if it's 'cleaned up' enough.

    <!-- Renders the list containing the Documents -->
    <xsl:template name="RenderNodes">
    <xsl:param name="documents" />
    <xsl:param name="page" />
    <xsl:param name="numDisplay" />

    <xsl:variable name="startPosition" select="($page * $numDisplay - $numDisplay) + 1" />
    <xsl:variable name="endPosition" select="$page * $numDisplay" />
    <div id="list-wrapper">
    <ul class="list">
    <xsl:for-each select="$documents">
    <xsl:sort select="./@createDate" order="descending" />
    <li>

    <xsl:variable name="focusImage" select="./data [@alias = 'PreviewImage1']"/>
    <xsl:if test="position() &gt;= $startPosition and position() &lt;= $endPosition">

    <xsl:choose>
    <xsl:when test="string($focusImage) != ''">
    <xsl:variable name="media" select="umbraco.library:GetMedia($focusImage, false)" />
    <a href="{umbraco.library:NiceUrl(./@id)}"><img alt="{$media/@nodeName}" src="{$media/data [@alias = 'umbracoFile']}" width="250" /></a>

    </xsl:when>
    <xsl:otherwise><img src="ROLLBACK IMAGE HERE" width="250" /></xsl:otherwise>
    </xsl:choose>

    <p><a href="{umbraco.library:NiceUrl(./@id)}"><xsl:value-of select="@nodeName"/></a></p>

    </xsl:if>

    </li>
    </xsl:for-each>
    </ul>
    </div>

    </xsl:template>

    Thanks again Rich.

    Sam.

Please Sign in or register to post replies

Write your reply to:

Draft