I am trying to understand how to make an image recursive in Xslt macro. I've
searched the forum for hours, tryng to find what I need, but no luck so
far. I would apriciate any help. I am not a programmer, and I have a
fairly small understanding of Xslt/Xpath. I mainly use open code and
change it to my (limited) understanding.
I'm using Umbraco 4.7
So basicly, I have an Xslt macro who makes a list of books the site
sells. Every book should have an image, but sometimes it doesn't, and
when it doesn't I'd like to show a default image which is in the
parent node.
Making an image recursive in Xslt macro
Hi,
I am trying to understand how to make an image recursive in Xslt macro. I've searched the forum for hours, tryng to find what I need, but no luck so far. I would apriciate any help. I am not a programmer, and I have a fairly small understanding of Xslt/Xpath. I mainly use open code and change it to my (limited) understanding.
I'm using Umbraco 4.7
So basicly, I have an Xslt macro who makes a list of books the site sells. Every book should have an image, but sometimes it doesn't, and when it doesn't I'd like to show a default image which is in the parent node.
this is the full code I have now:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<!-- The fun starts here -->
<div class="products_bg">
<ul class="products_list">
<xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
<xsl:call-template name="strip"></xsl:call-template>
</xsl:for-each>
<div class="clearfix"> </div>
</ul>
</div>
</xsl:template>
<xsl:template name="strip">
<li>
<div class="product_head">
<a href="{umbraco.library:NiceUrl(@id)}"><h2>
<xsl:value-of select="title" disable-output-escaping="yes"/></h2></a>
<h3 class="right">
<xsl:value-of select="autor" disable-output-escaping="yes"/> </h3>
<h3 class="left">
<xsl:value-of select="publishing" disable-output-escaping="yes"/> </h3>
<div class="clearfix"> </div>
</div>
<div class="product_info">
<div class="product_description">
<xsl:value-of select="shortDescription" disable-output-escaping="yes"/>
</div>
<div class="price">
<h4>
<xsl:value-of select="price" disable-output-escaping="yes"/> $</h4>
</div>
<a href="{umbraco.library:NiceUrl(@id)}" class="more_info">more info</a>
<xsl:value-of select="payPalLink" disable-output-escaping="yes"/>
</div>
<div class="product_image_holder">
<a href="{umbraco.library:NiceUrl(@id)}">
<img src="{img}" alt='{imageAlt}' title='{imgAlt}' />
</a>
</div>
<div class="clearfix"> </div>
</li>
</xsl:template>
</xsl:stylesheet>
The code worked perfectly so far, but now the client asked me to put this default image.
The specific image code is this line:
<img src="{img}" alt='{imageAlt}' title='{imgAlt}' />
Thank you so much to anyone who can help.
Hi Yael,
Here's a quick "fix" for your current code...
Add a template for the image before the final </xsl:stylesheet>:
And where you output it, use a recursive select:
/Chriztian
Hi Chriztian,
Your solution works great! And thank you so much for your quick response.
Have a great day!
Yael
is working on a reply...