Copied to clipboard

Flag this post as spam?

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


  • lucuma 261 posts 563 karma points
    Nov 17, 2010 @ 17:50
    lucuma
    0

    Get First Child Node

    I have a page that has a slideshow on it that I'd like to use the first image in the slideshow to display in some other summary.  Anyways, what is the best *logic* for doing this.. I know I can hack something together but I'd like to know if you would do this (pseduocode):

     

    Page
    -slideshow
    --image
    --image
    --image
    
    if count(images)>=1 then
      for-each image
        if position=1 then
           use this image
    
    OR is there some way to xpath the first image node and just check and use that without a for loop?
  • Rich Green 2246 posts 4008 karma points
    Nov 17, 2010 @ 18:01
    Rich Green
    0

    Hey lucuma,

    You shouldn't need to loop through all the images to find the first one, you should be able to use position=1 in your xpath to just grab the first one.

    Rich

  • lucuma 261 posts 563 karma points
    Nov 17, 2010 @ 18:17
    lucuma
    0

    Thanks that worked perfectly. Still a little new at the xlst stuff.  One more thing, if I want to select the first one based on a sortOrder (numeric attribute), am I forced to use the for-each or a template match?  It looks that way to me...

    edit: I think I've answered my own question.. I just need to check the attribute for sortOrder=1 or whatever (user just needs to know to make sure this is a sortOrder=1)...

    <xsl:if test="$projectinfo//slideShowImage [sortOrder=1]!=''">
                
           <img width="288" height="185" alt="">
      <xsl:attribute name="src" >
        <xsl:value-of select="$projectinfo//slideShowImage [sortOrder=1] /umbracoFile" />    
                </xsl:attribute>
          </img>
        </xsl:if>

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Nov 17, 2010 @ 19:01
    Stefan Kip
    0

    You should double check if sortOrder isn't a zero-based value ;-)

Please Sign in or register to post replies

Write your reply to:

Draft