Copied to clipboard

Flag this post as spam?

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


  • Liam 22 posts 158 karma points
    Oct 31, 2013 @ 16:43
    Liam
    0

    XSLT - if x and b not null then creating list item

    <xsl:variable name="media" select="umbraco.library:GetMedia($listingPage/node/data[@alias = 'icon'], 0)/data" />

    <xsl:variable name="link" select="umbraco.library:GetMedia($listingPage/node/data[@alias = 'contentLink'], 0)/data" />

    <xsl:for-each select="$listingPage/node">

    <xsl:choose>

    <xsl:when test="($media !='') and ($link !='')">

    <li>

    <xsl:variable name="url" select="$media[@alias = 'umbracoFile']" />

    ........................................

    All I want to do is check that each child node of $listingPage has something set for both $media and $link properties. 

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 31, 2013 @ 16:59
    Dennis Aaen
    0

    Hi Liam,

    Which version of Umbraco are you using.

    Looking forward to hear from you.

    /Dennis

  • Liam 22 posts 158 karma points
    Oct 31, 2013 @ 17:04
    Liam
    0

    Hi Dennis,

     

    Version 4.0.2.1 so the old schema?

     

    Cheers/

    Liam


  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 31, 2013 @ 17:19
    Chriztian Steinmeier
    0

    Hi Liam,

    You can include those criteria in the for-each so you're only processing items that have values in those properties:

    <xsl:for-each select="$listingPage/node[normalize-space(data[@alias = 'icon']) and normalize-space(data[@alias = 'contentLink'])]">
        ...
    </xsl:for-each>
    

    /Chriztian

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 31, 2013 @ 18:42
    Dennis Aaen
    0

    Yes you´re right version 4.0.2.1 use the old schema and from version 4.5 and further use the new schema per default.

    In your case this should work. I must say I don´t have spend so must time with the old schema, because I have implemented solutions on Umbraco 4.5 and newer. So I only use the old schema in a short periode of time.

    <xsl:variable name="media" select="umbraco.library:GetMedia($listingPage/data[@alias = 'icon'], 0)/data" />

    <xsl:variable name="link" select="umbraco.library:GetMedia($listingPage/data[@alias = 'contentLink'], 0)/data" />

    <xsl:choose>
        <xsl:when test="$media !='' and $link !='')">
            <xsl:for-each select="$listingPage/node">
                <li>
                    <xsl:variable name="url" select="$media[@alias = 'umbracoFile']" />
                </li>
            </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
         <!-- Do some other stuff-->
        </xsl:otherwise>
    </xsl:choose>

    By using the normalize-space as Chrizitan said you removes leading and trailing spaces from the specified string, and replaces all internal sequences of white space with one and returns the result. If there is no string argument it does the same on the current nod.

    Hope this helps.

    /Dennis

  • Liam 22 posts 158 karma points
    Nov 01, 2013 @ 11:57
    Liam
    100

    Hi,

    Sorry guys, tried both suggestions with no joy.

    Dennis, even if I got your rendering I fear it would be the same link and icon for every node found in my loop - Wouldn't I need both variables inside the foreach loop then use the "current()", like:

     

    <xsl:for-each select="$listingPage/node">

    <xsl:variable name="media" select="umbraco.library:GetMedia(current()/data[@alias = 'icon'], 0)/data" />

    <xsl:variable name="link" select="umbraco.library:NiceUrl(current()/data[@alias= 'contentLink'])" />

     

    Anyway I don't normally use a U version this old either so I ended up making both fields mandatory which means if a node is found they are both always there. 

    Thanks for the help everyone.

    Cheers.

    Liam

Please Sign in or register to post replies

Write your reply to:

Draft