Stylesheet to filter job postings by location

Welch, Ed's Avatar

Welch, Ed

08 Aug, 2012 02:12 PM

Hi,

I am working on updating our job postings page to organize openings by location, since we have five locations where we offer classes. Attached is a screenshot of the index block as well as the datadef and stylesheet, where I am attempting to filter openings by location, using a stylesheet I'm trying to repurpose for that list. The HR person maintaining the site selects the location choice from the dropdown and my idea is to have a listing filtered by each dropdown choice. I can't seem to get any output when I attempt to filter the "location" that's in the page data. Ideas?

I admit to infrequently tweaking styles in Cascade and being still rusty with xslt. Thought about doing something by content type but it might be too burdensome for the HR person to handle and redundant since the datadef handles page output listing location - I'd rather filter that data.

Ed Welch
Assistant Director of Communications and Web Coordinator
Southern Wesleyan University
864-644-5328
864-506-0419 (mobile)
www.swu.edu<http://www.swu.edu/>

[Description: SWU-Wordmark-160]<http://www.swu.edu/>

[Description: facebook1]<http://www.facebook.com/southernwesleyanuniversity.central> [Description: twitter1] <http://www.twitter.com/SWU_edu> [Description: linkedin1] <http://www.linkedin.com/company/southern-wesleyan-university> [Description: youtube1] <http://www.youtube.com/user/southernwesleyanuniv>

  1. Support Staff 2 Posted by Ryan Griffith on 08 Aug, 2012 03:13 PM

    Ryan Griffith's Avatar

    Hi Ed,

    Could you also attach the XML generated by the Index Block so I would be able to do some testing on my local instance? Thanks!

  2. 3 Posted by Welch, Ed on 08 Aug, 2012 03:31 PM

    Welch, Ed's Avatar

    Here it is...

    Ed

    XML removed and attached below.
    
  3. Support Staff 4 Posted by Ryan Griffith on 08 Aug, 2012 03:37 PM

    Ryan Griffith's Avatar

    Ed, hope you don't mind but I removed the pasted XML and attached it to this post.

  4. Support Staff 5 Posted by Ryan Griffith on 08 Aug, 2012 03:57 PM

    Ryan Griffith's Avatar

    Ed, just wanted to clarify, are you looking to output a list of links to all postings organized by location?

  5. 6 Posted by Welch, Ed on 08 Aug, 2012 04:03 PM

    Welch, Ed's Avatar

    Ryan,

    I want to break out the listing (see online http://swu.edu/hr/1-openings_faculty/index.htm ) into something like this:

    Employment Opportunities - Faculty

    Various Locations:
    Full-time -
    JOB POSTING1
    JOB POSTING2
    JOB POSTING3

    Part-time -
    JOB POSTING1
    JOB POSTING2
    JOB POSTING3

    Central:
    Full-time -
    JOB POSTING1
    JOB POSTING2
    JOB POSTING3

    Part-time -
    JOB POSTING1
    JOB POSTING2
    JOB POSTING3

    Charleston:
    Full-time -
    JOB POSTING1
    JOB POSTING2
    JOB POSTING3

    Part-time -
    JOB POSTING1
    JOB POSTING2
    JOB POSTING3

    Columbia:
    Full-time -
    JOB POSTING1
    JOB POSTING2
    JOB POSTING3

    Part-time -
    JOB POSTING1
    JOB POSTING2
    JOB POSTING3

    Greenville:
    Full-time -
    JOB POSTING1
    JOB POSTING2
    JOB POSTING3

    Part-time -
    JOB POSTING1
    JOB POSTING2
    JOB POSTING3

    North Augusta:
    Full-time -
    JOB POSTING1
    JOB POSTING2
    JOB POSTING3

    Part-time -
    JOB POSTING1
    JOB POSTING2
    JOB POSTING3

  6. Support Staff 7 Posted by Ryan Griffith on 08 Aug, 2012 06:29 PM

    Ryan Griffith's Avatar

    Hi Ed,

    You would definitely need to use the <xsl:key> element to group the pages by location. For more information about this XSLT element, see this page. The following should get you started:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:output encoding="UTF-8" indent="yes" method="xml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
    
        <!-- Define our key for lookups while looping. -->
        <xsl:key name="listing-location" match="location" use="." />
        
        <xsl:template match="/system-index-block">
            <!-- Loop through each location in our key -->
            <xsl:for-each select="//system-page/system-data-structure/location[count(. | key('listing-location', .)[1]) = 1]">
                <!-- Sort the locations alphabetically. -->
                <xsl:sort select="." data-type="text"/>
                
                <xsl:variable name="currentLocation" select="." />
                
                <!-- Output the value of the current location -->
                <h1><xsl:value-of select="$currentLocation"/></h1>      
                <ul>
                    <!-- Display the info for each page containing the current location. -->
                    <xsl:apply-templates select="../../../system-page[system-data-structure/location=$currentLocation]"/>
                </ul>
            </xsl:for-each>
        </xsl:template>
        
        <xsl:template match="system-page">
            <li>
                <a href="{path}"><xsl:value-of select="display-name"/></a>
            </li>
        </xsl:template>
    </xsl:stylesheet>
    

    Note: there was quite a bit of code that was unnecessary so I hope you don't mind that I started from scratch.

    One suggestion may be to add an additional "Job Length" field that identifies the posting as Full Time or Part Time, this way you can easily sort or display listings based on this value (like your example output above).

    Please let me know if you have any questions.

    Thanks.

  7. 8 Posted by Welch, Ed on 08 Aug, 2012 06:34 PM

    Welch, Ed's Avatar

    I'll give it a try. Thanks, Ryan.

    Ed

  8. 9 Posted by Welch, Ed on 08 Aug, 2012 06:52 PM

    Welch, Ed's Avatar

    Ryan,

    Okay this looks good.

    If I were to add a "job-length" field to break out fulltime and part-time, I'm sorting through the data using two different criteria. Does it make more sense for me to output data like this?

    Full-Time positions
    Various locations
    -Job posting
    -Job posting
    Central
    -Job posting
    -Job posting
    Charleston
    -Job posting
    -Job posting

    Part-Time positions
    Various locations
    -Job posting
    -Job posting
    Central
    -Job posting
    -Job posting
    Charleston
    -Job posting
    -Job posting

    Or can I do the breakdown under each location? I guess I'm still trying to get my head around how to style that. Thanks for your help!

    Ed

  9. Support Staff 10 Posted by Ryan Griffith on 08 Aug, 2012 07:04 PM

    Ryan Griffith's Avatar

    You could go either way there. I believe you would have to create a second key and do something similar to my example, but nested under one another.

    As for the structure, it really depends on the audience. You may want to ask which is more important to the end-user while scanning, location or length, and go from there.

  10. 11 Posted by Welch, Ed on 08 Aug, 2012 07:10 PM

    Welch, Ed's Avatar

    Okay. I'll try doing a second key and nesting. Thanks, Ryan.

    Ed

  11. Support Staff 12 Posted by Ryan Griffith on 08 Aug, 2012 07:13 PM

    Ryan Griffith's Avatar

    Not a problem, Ed. Also, would it be alright if I make this discussion public? Perhaps someone from the community may chime in as well.

  12. 13 Posted by Welch, Ed on 08 Aug, 2012 07:24 PM

    Welch, Ed's Avatar

    Sounds good. Thanks again, Ryan.

    Ed

  13. Tim closed this discussion on 27 Aug, 2012 05:18 PM.

Comments are currently closed for this discussion. You can start a new one.