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..
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".
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 :)
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"><a href="#"><img src="images/butt_download_details.png" width="117" height="21" alt="Download Details" /></a></div>
<div class="prdButtAdd"><a 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.
Hi Sam,
I think the problem is you are referencing productNew in the xsl:if statement using the old schema syntax. Try replacing with:
-Tom
Thats it!!!
Solved...thank you very much Tom.
Sam.
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:
/Chriztian
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 :)
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
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
is working on a reply...