Copied to clipboard

Flag this post as spam?

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


  • Sam 63 posts 126 karma points
    Apr 07, 2011 @ 14:28
    Sam
    0

    Check for true/false property and return value in XSLT

    HI all, have a problem with a true/false property taht i've use in a document type...haven't figured out how to check if the true/false checkbox is check or not in xslt and write the corresponding html attribute to it..

     

    MY CODE: 

    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
     
    <xsl:sort order="descending" select="@createDate"/> 
       
    <div class="prdLt">
    <xsl:value-of select="productNew"/>               
      
    <xsl:if test="string(./data [@alias = 'productNew']) = '1'">
       <div>div with new image tag comes here</div>
    </xsl:if>
       
        <div class="prdBox1">
             <div class="prdImg"><img src="{productPhoto}" width="180" height="140" alt="{@nodeName}" /></div>
             <div class="prdName"><xsl:value-of select="productName"/></div>
        </div>
        <div class="prdBox2">
             <div class="prdDesc"><xsl:value-of select="productDescription" disable-output-escaping="yes"/></div>
             <div class="prdButtons">
                <div class="prdButtDownload"><href="#"><img src="images/butt_download_details.png" width="117" height="21" alt="Download Details" /></a></div>
                <div class="prdButtAdd"><href="#"><img src="images/butt_add_basket.png" width="107" height="21" alt="Add to Basket" /></a></div>
             </div>
        </div>
      
      
    </div>
      
    </xsl:for-each>

     

    Let me explain..i have sort of a product catalogue with the option to add a tag NEW if its a new product.

     

    when i use the value-of select="productNew"/>...its returning me the good values 1 for check and o for not check...but its not publishing the divs.

     

    PLEASE HELP.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 07, 2011 @ 14:31
    Tom Fulton
    0

    Hi Sam,

    I think the problem is you are referencing productNew in the xsl:if statement using the old schema syntax.  Try replacing with:

    <xsl:if test="string(./productNew) = '1'">

    -Tom

  • Sam 63 posts 126 karma points
    Apr 07, 2011 @ 14:55
    Sam
    0

    Thats it!!!

    Solved...thank you very much Tom.

    Sam.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Apr 07, 2011 @ 21:17
    Chriztian Steinmeier
    2

    Hi Sam (+Tom),

    You can actually get away with this: <xsl:if test="productNew"> because a test like that will actually be silently performed as: boolean(productNew) - which will return true() for 1 and false() for 0. Handy.

    But sometimes I'd actually do something like this instead:

    <xsl:template match="/">
        <xsl:for-each select="...">
    
            <div class="prdLt">
                ...
                <xsl:apply-templates select="productNew[. = 1]" />
                ...
            </div>
    
        </xsl:for-each>
    </xsl:template>
    
    <xsl:template match="productNew">
        <div>div with new image tag comes here</div>
    </xsl:template>
    
    The "filter" - [. = 1] - makes sure that the productNew element is only processed if it's set to 1.
    I know it's a *completely* different mindset, but it's actually pretty neat, and works a bit like a typical "one-liner".

    /Chriztian 

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 07, 2011 @ 21:51
    Tom Fulton
    0

    Very cool, thanks Chriztian.  I am slowly starting to use apply-templates after reading and implementing your last blog post about MNTP and I definately like them so far.  Still a few things to work out though :)

  • Sam 63 posts 126 karma points
    Apr 08, 2011 @ 06:17
    Sam
    0

    Seems really neat coding.. : )
    Must investigate a bit on it though.
    Thks Chriztian.

  • asim 16 posts 36 karma points
    Apr 29, 2011 @ 00:46
    asim
    0

    Hi all

    i wana implement the same condition for  check box but from parent node

    i.e I wana  make sure if the check box in parent node is checked for banner image, then banner will be included in child pages.

    any idea how to get the parent node check_box in XSLT

     

    thanx

    Asim

  • asim 16 posts 36 karma points
    Apr 29, 2011 @ 08:19
    asim
    0

    Hi Jan

    i wana do the checkbox condition from child page, and checkbox is in parent page for banner image, as explanned in previous post.

    will this code work?

    $currentPage/ancestor-or-self::node [position()=1] /data [@alias='subPageImage_nl'] = 1

    v4.7

    thanx

    Asim

Please Sign in or register to post replies

Write your reply to:

Draft