Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon 24 posts 64 karma points
    Jul 15, 2010 @ 12:09
    Simon
    0

    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"/>&nbsp;  

      (<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>

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 15, 2010 @ 12:16
    Ismail Mayat
    0

    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)&gt;0 in the otherwise clause show text no results found.

    Regards

     

    Isamil

  • Simon 24 posts 64 karma points
    Jul 15, 2010 @ 12:31
    Simon
    0

    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

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 15, 2010 @ 12:38
    Ismail Mayat
    0

    Simon,

    Can you paste your xslt in full that will give better idea of what you are trying todo.

    Regards

    Ismail

  • Simon 24 posts 64 karma points
    Jul 15, 2010 @ 12:39
    Simon
    0

    <?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" 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"/>&nbsp;
      

      (<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>

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Jul 15, 2010 @ 13:39
    Nik Wahlberg
    0

    Hi there, what about something like this? If I understand your XSLT correct, then this should do it (basically what ismail suggested above).

            <xsl:choose>
              <xsl:when test="count($source/node[@nodeTypeAlias=$documentTypeAlias])&gt;0">
                <xsl:apply-templates select="$source/node[@nodeTypeAlias=$documentTypeAlias]">
                  <xsl:sort select="@createDate" data-type = "number" order="descending"/>
                </xsl:apply-templates>
              </xsl:when>
              <xsl:otherwise>
                <p>No Jobs dude!</p>
              </xsl:otherwise>
            </xsl:choose>

    Cheers,
    Nik

  • Simon 24 posts 64 karma points
    Jul 15, 2010 @ 14:41
    Simon
    0

    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.

  • Simon 24 posts 64 karma points
    Jul 15, 2010 @ 15:07
    Simon
    0

    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.

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Jul 15, 2010 @ 15:09
    Nik Wahlberg
    0

    Cool, glad I could help! 

Please Sign in or register to post replies

Write your reply to:

Draft