Copied to clipboard

Flag this post as spam?

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


  • FarmFreshCode 225 posts 422 karma points
    Oct 02, 2013 @ 22:20
    FarmFreshCode
    0

    Using CONTAINS to get all results possible

    My XML looks like this:

    <FacultyProfile id="6828" parentID="6394" level="3" writerID="21" creatorID="11" nodeType="6392" template="6397" sortOrder="147" createDate="2013-05-29T09:59:29" updateDate="2013-09-12T08:58:48" nodeName="Alice Noblin" urlName="alice-noblin" writerName="dj" creatorName="ABell" path="-1,1100,6394,6828" isDoc="">
    
        <facultyDepartment><![CDATA[department 1,department 2]]></facultyDepartment>
    
        <facultyResearchInterests><![CDATA[personal health records,electronic health records]]></facultyResearchInterests>
    
    
        </FacultyProfile>
    

    On rare occasions, my directory of members are associated with multiple departments (as shown above). This prevents me from properly calling them the way I currently know how to. Which is:

    <xsl:for-each select="$rootNode/FacultyProfile [facultyDepartment='department 1'][string-length(facultyResearchInterests) != 0]">
    

    Is it possible to use CONTAINS to replace the call:

    [facultyDepartment='department 1']
    

    because that it preventing any results that have that 'department 1' as well as another one from being displayed? Am I right in thinking that CONTAINS is the answer at all?

    Thank you everyone in advance.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Oct 04, 2013 @ 00:12
    Chriztian Steinmeier
    100

    Hi FarmFreshCode,

    Yes - you can use contains() to do that, like this:

    <xsl:for-each select="$rootNode/FacultyProfile[contains(facultyDepartment, 'department 1')][normalize-space(facultyResearchInterests)]">
    

    - only thing you need to be aware of is if you have departments/categories like these: our, flour - because 'our' is contained inside flour, it will surface as a "false positive" - to prevent that, one normally surrounds the terms with the separator character, so that you effectively search forthe string ',our,' within ',our,flour,' so that only the perfect match comes out - like this:

    <xsl:variable name="sep" select="','" />
    <xsl:for-each select="$rootNode/FacultyProfile[contains(concat($sep, facultyDepartment, $sep), concat($sep, 'department 1', $sep))][normalize-space(facultyResearchInterests)]">
    

    Finally, the best (I think) way is using the Split() extension to get each checked department as a separate value, and then compare with the searched value - this works because of the way XSLT works with (almost) everything being a nodeset:

    <xsl:for-each select="$rootNode/FacultyProfile[umbraco.library:Split(facultyDepartment, ',')/value = 'department 1'][normalize-space(facultyResearchInterests)]">
    

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft