Test for image in list? Options
subzip
Posted: Tuesday, June 24, 2008 3:38:28 PM

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 "&#x00A0;"> ]>
<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')) &lt;=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() &lt;= 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 &gt;0">
<a href="?side={$pageNumber -1}">&#171; Forrige side</a>&nbsp;&nbsp;
</xsl:if> 
 
<xsl:if test="(($pageNumber +1) * $recordsPerPage) &lt;($numberOfRecords)"> 
<a href="?side={$pageNumber +1}">Næste side &#187;</a> 
</xsl:if></p>
<!-- Listen -->
</xsl:template>

</xsl:stylesheet>


Can anyone please help?
Thanks!Think

Regards,
Kenneth Rasmussen
mortenbock
Posted: Tuesday, June 24, 2008 4:32:57 PM

Rank: Addict

Joined: 7/19/2006
Posts: 738
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.

Morten Bock - Level 2 certified - MVP 2008/2009 - My danish blog with a few english posts

subzip
Posted: Tuesday, June 24, 2008 5:00:01 PM

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
mortenbock
Posted: Tuesday, June 24, 2008 7:30:24 PM

Rank: Addict

Joined: 7/19/2006
Posts: 738
Location: Århus, Denmark
Ahhh, just looked properly at the code...

Try this:

Code:

<xsl:when test="./data [@alias='thumbfoto'] != ''">


Morten Bock - Level 2 certified - MVP 2008/2009 - My danish blog with a few english posts

subzip
Posted: Tuesday, June 24, 2008 8:13:05 PM

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
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.