Copied to clipboard

Flag this post as spam?

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


  • J 447 posts 864 karma points
    Oct 24, 2013 @ 22:44
    J
    0

    Multiple If statement

    Im trying to get one image back from a media library (but same procedure would be used against other items i.e. News).

    So heres the code i have 

    <xsl:for-each select="umbraco.library:GetXmlNodeById(1)/descendant::* [@isDoc]">

    <xsl:if test="image !=''">

    which works.... so i now want to check two conditions. Second condition is if the for each has multiple items the to get one, so created a variable to hold the value

    <xsl:variable name="items" select="1" />

    So i would like one item to be returned regardless of the number of items. My code now is

    <xsl:if test="image !=''" and (&lt; $items)>

    but get an error. How should i be checking these multiple conditions?

    Thanks

     

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 24, 2013 @ 22:55
    Chriztian Steinmeier
    0

    Hi J,

    Am I right in thinking that you want to render the first X items that has an image, regardless how many there are?

    If so, try this:

    <xsl:variable name="source" select="umbraco.library:GetXmlNodeById(1)" />
    <xsl:variable name="items" select="1" />
    
    <!-- Grab all nodes below $source that have an image defined -->
    <xsl:for-each select="$source//*[@isDoc][normalize-space(image)]">
        <xsl:if test="position() &lt;= $items">
            ...
        </xsl:if>
    </xsl:for-each>
    

    Otherwise, let us know what you're trying to achieve—

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft