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 @ 14:56
    FarmFreshCode
    0

    Filter XML by multiple variables

    I have a directory of people. Each person in that directory has various standardized pieces of information. For example, phone #, email, department, etc...

    What I need is a way to filter out specific results based on values that each person may have. In this specific case I need logic like this:

    If a person works in "Department 1" AND has any "Research Interests" listed THEN display them in a list on nodeID 1234.

    I have been able to do something close so far by using this line:

    <filter id="6623" property="Department" value="Technology" />
    

    But as you can see this only pulls people that work in the Technology Department and displays them on a page with a nodeID of 6623.

    Here is an example of my XML data.

    <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="">
    
    <facultyResearchInterests><![CDATA[personal health records (PHR),electronic health records (EHR),health information exchange (HIE),patient engagement,health literacy]]></facultyResearchInterests>
    
    <facultyDepartment><![CDATA[Health Management]]></facultyDepartment>
    
    </FacultyProfile>
    

    As you can see my root node for the Directory is 6394. How do I create a XSLT script to pull people based on multiple factors and display NodeName and Research Interests of each person that applies within that Department's page?

    Thank you everyone in advance!

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Oct 02, 2013 @ 16:23
    Ismail Mayat
    0

    What does your xslt look like?

    Ismial

  • Stephen 767 posts 2273 karma points c-trib
    Oct 02, 2013 @ 16:47
    Stephen
    0

    What you want is an XPath query that will select all FacultyProfile nodes under node 6394, which are in a given department and have interests listed?

    <xsl:for-each select="//* [@id=6394]/FacultyProfile [facultyDepartment='Health Management' and string(facultyResearchInterest) != '']">
      <div>Name: <xsl:value-of select="./@name" />
    </xsl:for-each>

    ?

  • FarmFreshCode 225 posts 422 karma points
    Oct 02, 2013 @ 18:04
    FarmFreshCode
    0

    Hello Stephen,

    Thank you for your response. I didn't include this before but I'm using umbraco v 4.8.1 just in case that matters.

    I tried your code:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet>
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    
    <xsl:param name="currentPage"/>
    <xsl:template match="/">
    
    <xsl:for-each select="//* [@id=6394]/FacultyProfile [facultyDepartment='Health Management' and string(facultyResearchInterest) != '']">
      <div>Name: <xsl:value-of select="./@name" /></div>
    </xsl:for-each>
    
    </xsl:template>
    </xsl:stylesheet>
    

    I used this XSLT file in a Macro and then placed the Macro on a testing page for my site and wasn't able to generate any results. However as I am going to need to use this kind of script more than just one (example on a different department page) is there a way to include...

    IF nodeID = 1234 THEN

    <xsl:for-each select="//* [@id=6394]/FacultyProfile [facultyDepartment='Health Management' and string(facultyResearchInterest) != '']">
          <div>Name: <xsl:value-of select="./@name" /></div>
        </xsl:for-each>
    

    IF nodeID = 2234 THEN

    <xsl:for-each select="//* [@id=6394]/FacultyProfile [facultyDepartment='DEPARTMENT 2' and string(facultyResearchInterest) != '']">
          <div>Name: <xsl:value-of select="./@name" /></div>
        </xsl:for-each>
    

    ETC.....

    That would allow me to just create one XSLT file to manage for all of the various pages that need this kind of result listing.

  • FarmFreshCode 225 posts 422 karma points
    Oct 02, 2013 @ 19:11
    FarmFreshCode
    0

    OK.. I figured it out a little bit..

    It works if I take out the

    and string(facultyResearchInterest) != ''
    

    Could this be because "facultyResearchInterest" is using the TAGS datatype? I know tags seems to cause me problems sometimes.

  • FarmFreshCode 225 posts 422 karma points
    Oct 02, 2013 @ 19:18
    FarmFreshCode
    100

    Progress... this script works:

    <xsl:template match="/">
    <xsl:variable name="rootNode" select="umbraco.library:GetXmlNodeById(6394)" />
    
    <xsl:for-each select="$rootNode/FacultyProfile [facultyDepartment='Health Management and Informatics' and string-length(facultyResearchInterests) != 0]">
      <div>
        <xsl:value-of select="@nodeName" /><br/>
        <xsl:value-of select="umbraco.library:Replace(facultyResearchInterests, ',', ', ')" disable-output-escaping="yes"/>
      </div>
    </xsl:for-each>
    
    
    </xsl:template>
    

    Now I just need a quick way to auto substitute the "Department" out depending on the current nodeID. (or something similar)

Please Sign in or register to post replies

Write your reply to:

Draft