Hi guys, i have tried googling and looking around on this forum but anything i find releated to loops i can't get to work with my personal problem. Basicaly we have a drop down box on our site which we can pick an area from and it brings back a list of jobs available for that area. This works, except that when there are no jobs in an area it simply displays the area name at the top of the page. What i would like it to do is to tell the user that there are no jobs. I thought i could do this by using a for loop type thing that adds 1 to a variable each time it pulls back a result, if it pulls no results back it will tell the user there were no jobs.
Here is the code used to pull back the jobs as it stands at the moment:
No need for loop wrap the whole thing in xsl:choose statement do a test there namely if count(umbraco.library:Split(data [@alias = 'location'],',')/value)>0 in the otherwise clause show text no results found.
Sorry buddy, im new to umbraco and im basicaly editing the code that our web developers created for us. Could you explain that in a little more detail? I only have a basic knowledge of XSLT from tweaking bits here and there.
Hi Nik, i'm part way there now, it seems to be ignoring the otherwise though. I left out <xsl:sortselect="@createDate"data-type="number"order="descending"/> because i wasnt sure what it did. Can you explain this to me? As it stands at the moment if there are no jobs it just states the location with nothing underneith, can't figure out why it does this.
Hi Nik sorry for being an idiot then, i was looking at the wrong bit in my code, i have sorted this now with your help, i didnt realise the code for it was actually in there the whole time, just had to change the bit between otherwise. doh! thanks for your help.
Creating a loop in XSLT
Hi guys, i have tried googling and looking around on this forum but anything i find releated to loops i can't get to work with my personal problem. Basicaly we have a drop down box on our site which we can pick an area from and it brings back a list of jobs available for that area. This works, except that when there are no jobs in an area it simply displays the area name at the top of the page. What i would like it to do is to tell the user that there are no jobs. I thought i could do this by using a for loop type thing that adds 1 to a variable each time it pulls back a result, if it pulls no results back it will tell the user there were no jobs.
Here is the code used to pull back the jobs as it stands at the moment:
<xsl:template match="node">
<div class="job">
<div class="joblink"><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/>
(<xsl:value-of select="./data[@alias='jobRef']"/>)
</a></div>
<!--<div class="jobindustry"></div>-->
<div class="joblocation">
<xsl:apply-templates select="umbraco.library:Split(data [@alias = 'location'],',')/value"/><!-- this shows location-->
</div>
<xsl:value-of select="data [@alias = 'teaser']"/><p></p> <!-- this pulls back job description-->
</div>
</xsl:template>
Simon,
No need for loop wrap the whole thing in xsl:choose statement do a test there namely if count(umbraco.library:Split(data [@alias = 'location'],',')/value)>0 in the otherwise clause show text no results found.
Regards
Isamil
Sorry buddy, im new to umbraco and im basicaly editing the code that our web developers created for us. Could you explain that in a little more detail? I only have a basic knowledge of XSLT from tweaking bits here and there.
Regards,
Simon
Simon,
Can you paste your xslt in full that will give better idea of what you are trying todo.
Regards
Ismail
<?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" indent="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="source" select="/macro/source/node"/>
<!-- Input the documenttype you want here -->
<xsl:variable name="documentTypeAlias" select="string('Job')"/>
<xsl:variable name="numberOfItems" select="/macro/numberOfItems"/>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="umbraco.library:RequestQueryString('careerslist')!=''">
<xsl:choose>
<xsl:when test="$source/node[@nodeTypeAlias=$documentTypeAlias and contains(data[@alias='location'],umbraco.library:RequestQueryString('careerslist'))]">
<!-- use year date filter -->
<xsl:apply-templates select="$source/node[@nodeTypeAlias=$documentTypeAlias and contains(data[@alias='location'],umbraco.library:RequestQueryString('careerslist'))]">
<xsl:sort select="@createDate" data-type = "number" order="descending"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="umbraco.library:GetDictionaryItem('lbl-no-jobs')"/><xsl:value-of select="umbraco.library:GetXmlNodeById(umbraco.library:RequestQueryString('careerslist'))/@nodeName"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$source/node[@nodeTypeAlias=$documentTypeAlias]">
<xsl:sort select="@createDate" data-type = "number" order="descending"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="node">
<div class="job">
<div class="joblink"><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/>
(<xsl:value-of select="./data[@alias='jobRef']"/>)
</a></div>
<!--<div class="jobindustry"></div>-->
<div class="joblocation">
<xsl:apply-templates select="umbraco.library:Split(data [@alias = 'location'],',')/value"/>
</div>
<xsl:value-of select="data [@alias = 'teaser']"/><p></p>
</div>
</xsl:template>
<xsl:template match="value">
<xsl:variable name="regionNode" select="umbraco.library:GetXmlNodeById(.)"/>
<xsl:value-of select="$regionNode/@nodeName"/><xsl:if test="position()!=last()"><xsl:text>,</xsl:text></xsl:if>
</xsl:template>
</xsl:stylesheet>
Hi there, what about something like this? If I understand your XSLT correct, then this should do it (basically what ismail suggested above).
Cheers,
Nik
Hi Nik, i'm part way there now, it seems to be ignoring the otherwise though. I left out <xsl:sort select="@createDate" data-type = "number" order="descending"/>
because i wasnt sure what it did. Can you explain this to me? As it stands at the moment if there are no jobs it just states the location with nothing underneith, can't figure out why it does this.
Hi Nik sorry for being an idiot then, i was looking at the wrong bit in my code, i have sorted this now with your help, i didnt realise the code for it was actually in there the whole time, just had to change the bit between otherwise. doh! thanks for your help.
Cool, glad I could help!
is working on a reply...