|
|
 Rank: Enthusiast
Joined: 4/29/2007 Posts: 18 Location: DK
|
I have created a XSLT-productlist, which works almost perfect, but... I would like to test the "thumbfoto" string for an image, and if there is no image, then I want the code to display an alternative image, ex. "nofoto.gif". For now, nothing happens when using following: Code:<xsl:choose> <xsl:when test="string($currentPage/node [string(data [@alias='thumbfoto']) != ''])"> <a href="{umbraco.library:NiceUrl(@id)}"><img src="{concat(substring-before(./data [@alias='thumbfoto'],'.'), '_thumb.jpg')}" alt="Vis produkt" /></a> </xsl:when> <xsl:otherwise> <img src="/img/nofoto.gif" alt="Intet foto" /> </xsl:otherwise> </xsl:choose> Full XSLT:Code:<?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" exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="recordsPerPage" select="10"/> <xsl:variable name="pageNumber" > <xsl:choose> <!-- first page --> <xsl:when test="number(umbraco.library:RequestQueryString('side')) <=0 or string(umbraco.library:RequestQueryString('side')) = '' or string(number(umbraco.library:RequestQueryString('side'))) = 'NaN'"> 0 </xsl:when> <!-- what was passed in --> <xsl:otherwise> <xsl:value-of select="umbraco.library:RequestQueryString('side')"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="numberOfRecords" select="count($currentPage/node [string(data [@alias='umbracoNaviHide']) != '1'])"/>
<!-- The fun starts here -->
<!-- Listen --> <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
<xsl:if test="position() > $recordsPerPage * number($pageNumber) and position() <= number($recordsPerPage * number($pageNumber) + $recordsPerPage )"> <div class="ProductWrap"> <div class="PFoto">
<xsl:choose> <xsl:when test="string($currentPage/node [string(data [@alias='thumbfoto']) != ''])"> <a href="{umbraco.library:NiceUrl(@id)}"><img src="{concat(substring-before(./data [@alias='thumbfoto'],'.'), '_thumb.jpg')}" alt="Vis produkt" /></a> </xsl:when> <xsl:otherwise> <img src="/img/nofoto.gif" alt="Intet foto" /> </xsl:otherwise> </xsl:choose>
</div> <div class="TextWrap"> <div class="PText"><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a><br /><xsl:value-of select="substring(./data [@alias = 'MetaDesc'], 1, 500)" disable-output-escaping="yes"/></div> <div class="PBtn"><a href="{umbraco.library:NiceUrl(@id)}"><img src="/img/btn_show.jpg" alt="Vis produkt" /></a></div> </div> </div> </xsl:if> </xsl:for-each> <p class="pages"><xsl:if test="$pageNumber >0"> <a href="?side={$pageNumber -1}">« Forrige side</a> </xsl:if> <xsl:if test="(($pageNumber +1) * $recordsPerPage) <($numberOfRecords)"> <a href="?side={$pageNumber +1}">Næste side »</a> </xsl:if></p> <!-- Listen --> </xsl:template>
</xsl:stylesheet> Can anyone please help? Thanks!
Regards, Kenneth Rasmussen
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 739 Location: Århus, Denmark
|
Try doing a copy-of to see what actually comes out in the property: Code: <xsl:copy-of select="./data [@alias='thumbfoto']" />
You are using the Upload datatype right? Maybe it is outputting some xml, or returns a 0 or something. Look it the html source of the rendered page and see what the copy-of spits out.
|
|
 Rank: Enthusiast
Joined: 4/29/2007 Posts: 18 Location: DK
|
mortenbock wrote:Try doing a copy-of to see what actually comes out in the property: Code: <xsl:copy-of select="./data [@alias='thumbfoto']" />
You are using the Upload datatype right? Maybe it is outputting some xml, or returns a 0 or something. Look it the html source of the rendered page and see what the copy-of spits out. It shows absolutly nothing (whick is ok, as it in this case actully is emty): <data alias="thumbfoto" /></div> Other filled data types: ex: <data alias="thumbfoto">/media/400-calypso-front600.jpg</data>
Regards, Kenneth Rasmussen
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 739 Location: Århus, Denmark
|
Ahhh, just looked properly at the code... Try this: Code: <xsl:when test="./data [@alias='thumbfoto'] != ''">
|
|
 Rank: Enthusiast
Joined: 4/29/2007 Posts: 18 Location: DK
|
Yeehaaa, it works!! :d/
You are then man, Morten!!! (eller dagens mand i skyskovs, om man vil )
Regards, Kenneth Rasmussen
|
|
|
Guest |