?
Solved

xslt filtering - sorting

Posted on 2007-07-26
11
Medium Priority
?
204 Views
Last Modified: 2013-11-18
What I need to accomplish
I would like to have a web page that has:
FACULTY:
    A-H    I-P    Q-Z
and when I choose one all faculty menbers with the last name beginning with that letter would show up.
I am looking for best practices - I am using MS
the xml file:
  <Content>
    <ID>7450</ID>
      <Type>Content</Type>
      <Title>Baldwin, Ilene</Title>
      <QuickLink>/chp/faculty/detail.aspx?id=7450</QuickLink>
      <Teaser></Teaser>
      <Html>
        <root>
          <Photo><img alt="Baldwin, Illene - photo" src="/uploadedImages/CHP/Faculty/ilenebaldwin.jpg" /></Photo>
            <Name>Baldwin, Ilene</Name>
            <Title>Clerk</Title>
            <Department>Dean's Office</Department>
            <OfficeLocation>G156</OfficeLocation>
            <Telephone>708.534.4388</Telephone>
            <fax>708.534.8958</fax>
            <email>i-baldwin@govst.edu</email>
            <Education></Education>
            <Publications></Publications>
            <Honors></Honors>
            <Presentations></Presentations>
            <Research></Research>
            <Service></Service>
            <ProfessionalMemberships></ProfessionalMemberships>
         </root>
      </Html>
      <StartDate>1/1/0001 12:00:00 AM</StartDate>
      <DateModified>6/26/2007 10:56:12 AM</DateModified>
      <DateCreated>6/1/2007 10:53:27 AM</DateCreated>
      <EndDate>12/31/9999 11:59:59 PM</EndDate>
      <LastEditorFname>Mike</LastEditorFname>
      <LastEditorLname>Hopkins</LastEditorLname>
      <Hyperlink><a href="/chp/faculty/detail.aspx?id=7450">Baldwin, Ilene</a></Hyperlink>
      <DisplayStartDate></DisplayStartDate>
      <FolderID>676</FolderID>
      <ContentStatus>A</ContentStatus>
      <Language>1033</Language>
      <DisplayDateModified>6/26/2007 10:56:12 AM</DisplayDateModified>
      <DisplayDateCreated>6/1/2007 10:53:27 AM</DisplayDateCreated>
      <DisplayEndDate></DisplayEndDate>
      <EndDateAction>Archive_Expire</EndDateAction>
      <Comment></Comment>
  </Content>
0
Comment
Question by:bcrooks
  • 7
  • 4
11 Comments
 
LVL 13

Expert Comment

by:R7AF
ID: 19577036
I don't understand what you're trying to sort or filter. You can for instance sort on name, but I see only one name here. For filtering it's the same. If I want to filter all names beginning with A-H, I need a list of names. Maybe you don't want to publish a very long xml here.

If I would use the following XML, would that be okay to show the principle? I've deleted many nodes that are not relevant (from my viewpoint). If not modify the xml yourself. Notice that I use values that mimick the tagnames, so they are easy to identify in the resulting html.

<?xml version="1.0" encoding="UTF-8"?>

<data>
<Content>
      <ID>7450</ID>
      <Type>Content</Type>
      <Title>Baldwin, Ilene</Title>
      <QuickLink>/chp/faculty/detail.aspx?id=7450</QuickLink>
      <Teaser></Teaser>
      <Html>
            <root>
                  <Name>Baldwin, Ilene</Name>
                  <Title>Clerk</Title>
                  <email>i-baldwin@govst.edu</email>
            </root>
      </Html>
</Content>
<Content>
      <ID>6890</ID>
      <Type>Content</Type>
      <Title>Title2</Title>
      <QuickLink>/chp/faculty/link2.aspx?id=7450</QuickLink>
      <Teaser></Teaser>
      <Html>
            <root>
                  <Name>Name2</Name>
                  <Title>Title2</Title>
                  <email>email2</email>
            </root>
      </Html>
</Content>
<Content>
      <ID>3200</ID>
      <Type>Content</Type>
      <Title>XYZ Title3</Title>
      <QuickLink>/chp/faculty/link3.aspx?id=7450</QuickLink>
      <Teaser></Teaser>
      <Html>
            <root>
                  <Name>XYZ Name3</Name>
                  <Title>Title3</Title>
                  <email>email3</email>
            </root>
      </Html>
</Content>
</data>
0
 

Author Comment

by:bcrooks
ID: 19577104
I did'nt include all the names 100+
I know how to sort and filter an entire field, but I don't know how to code
if right(title,1) is between a-f
in a filter
0
 
LVL 13

Expert Comment

by:R7AF
ID: 19577168
>> if right(title,1) is between a-f

Can you say this in normal English? What do you mean with "right"?
Or give the filter and sort xslt that you have. That would make things a lot easier.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:bcrooks
ID: 19577187
if the first position of the last name is between the letters a thru f then show those records
0
 

Author Comment

by:bcrooks
ID: 19577242
This xsl filters out by department:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    exclude-result-prefixes="msxsl"
    >
  <xsl:param name="filter">Occupational Therapy</xsl:param>

  <xsl:param name="sortedContent">
    <Collection>
      <xsl:for-each select="/Collection/Content">
        <xsl:sort select="Html/root/Name" />
        <Content>
          <QuickLink>
            <xsl:copy-of select="QuickLink"/>
          </QuickLink>

          <Photo>
            <xsl:copy-of select="Html/root/Photo"/>
          </Photo>

          <Name>
            <xsl:copy-of select="Html/root/Name"/>
          </Name>
          <Department>
            <xsl:copy-of select="Html/root/Department"/>
          </Department>

          <OfficeLocation>
            <xsl:copy-of select="Html/root/OfficeLocation" />
          </OfficeLocation>

          <Telephone>
            <xsl:copy-of select="Html/root/Telephone" />
          </Telephone>

          <fax>
            <xsl:copy-of select="Html/root/fax" />
          </fax>

          <email>
            <xsl:copy-of select="Html/root/email" />
          </email>

        </Content>
      </xsl:for-each>
    </Collection>
  </xsl:param>

  <xsl:template match="/">
    <div align="center">
      <table cellspacing="3" cellpadding="3" width="700px">
        <xsl:for-each select="msxsl:node-set($sortedContent)//Content[Department = $filter]" >
          <tr>
            <td valign="top" align="left" >

              <xsl:if test="Photo">
                <a href="{QuickLink}">
                  <xsl:copy-of select="Photo" />
                </a>
              </xsl:if>
              <br />
            </td>

            <td valign="top" align="left">
              <a href="{QuickLink}">
                <span class="chp_highlight_bold">
                  <xsl:value-of select="Name" />
                </span>
              </a>
              <br />
              <xsl:value-of select="Department" />
              <br />
              <xsl:value-of select="OfficeLocation" />
              <br />
              <xsl:value-of select="Telephone" />
              <br />
              <xsl:value-of select="fax" />
              <br />
              <xsl:if test="email">
                <a href="mailto:{email}">
                  <xsl:value-of select="email" />
                </a>
              </xsl:if>


              <br />
              <br />
            </td>

          </tr>
        </xsl:for-each>
      </table>
    </div>
  </xsl:template>

</xsl:stylesheet>
0
 
LVL 13

Expert Comment

by:R7AF
ID: 19577965
I think the parameter sortedContent should be a template. But you call a variable sortedContent elsewhere. I think you're mixing things up. But on the other hand you're using some msxsl functions, which I never use, so you may be doing something I don't know about.
0
 
LVL 13

Expert Comment

by:R7AF
ID: 19578073
The following xslt is based on my shortened xml. I filter on the Title. I don't know what you wanted to do with the sortedContent parameter, but I hope this is more or less what you need. If you need to copy xml (xsl:copy-of), then that can be done of course.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
            version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:msxsl="urn:schemas-microsoft-com:xslt"
            exclude-result-prefixes="msxsl">
            
      <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
      <xsl:variable name="filter">Title2</xsl:variable>

      <xsl:template match="/">
            <div align="center">test
                  <table cellspacing="3" border="1px" cellpadding="3" width="700px">
        <!--  <xsl:for-each select="msxsl:node-set($sortedContent)//Content[Department = $filter]" > -->
                        <xsl:for-each select="/Collection/Content[Html/root/Title=$filter]">
                              <xsl:sort select="Html/root/Name" />
                              <tr>
                                    <td valign="top" align="left">
                                          <xsl:value-of select="Html/root/Title" />
                                    </td>
                                    <td valign="top" align="left">
                                          <xsl:if test="Html/root/email">
                                                <a href="mailto:{Html/root/email}">
                                                      <xsl:value-of select="Html/root/email" />
                                                </a>
                                          </xsl:if>
                                    </td>
                              </tr>
                        </xsl:for-each>
                  </table>
            </div>
      </xsl:template>

</xsl:stylesheet>
0
 

Author Comment

by:bcrooks
ID: 19578729
I don't see how this only will show those with last names that begin with a thru f?
0
 
LVL 13

Expert Comment

by:R7AF
ID: 19578776
Ah yes! Sorry, forgot that. I will look at that tomorrow.
0
 
LVL 13

Accepted Solution

by:
R7AF earned 2000 total points
ID: 19582624
Okay, I think I have a solution. I use an extra xml file (first.xml) which has three sets of characters in it (A-H, I-P and Q-Z) in three sets. I use this to match for the first letter. Save this xml as a seperate file. It is called using the document function. You have to put it in the same directory, but changing the path you can put it anywhere you like, even on a different domain. Or if you want, you can include this xml in your other xml.

You probably have to fix the xml to match your wishes, as it matches against other nodes than you want. But it shows the principle. I hope this is good enough and that you're able to adjust it yourself. If not, let me know.

#################### XSLT ####################

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
            version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:msxsl="urn:schemas-microsoft-com:xslt"
            exclude-result-prefixes="msxsl">
            
      <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
      
      <xsl:template match="Collection">
            <xsl:variable name="sets" select="document('first.xml')/sets"/>
            <div align="center">test
                  <table cellspacing="3" border="1px" cellpadding="3" width="700px">
                        <xsl:for-each select="Content[substring(Title,1,1)=$sets/set[@select='Q']/c]">
                              <xsl:sort select="Html/root/Name" />
                              <tr>
                                    <td valign="top" align="left">
                                          <xsl:value-of select="Title" />
                                    </td>
                                    <td valign="top" align="left">
                                          <xsl:if test="Html/root/email">
                                                <a href="mailto:{Html/root/email}">
                                                      <xsl:value-of select="Html/root/email" />
                                                </a>
                                          </xsl:if>
                                    </td>
                              </tr>
                        </xsl:for-each>
                  </table>
            </div>
      </xsl:template>

</xsl:stylesheet>

#################### first.xml ####################

<?xml version="1.0" encoding="UTF-8"?>

<sets>
      <set select="A">
            <c>A</c>
            <c>B</c>
            <c>C</c>
            <c>D</c>
            <c>E</c>
            <c>F</c>
            <c>G</c>
            <c>H</c>
      </set>
      <set select="I">
            <c>I</c>
            <c>J</c>
            <c>K</c>
            <c>L</c>
            <c>M</c>
            <c>N</c>
            <c>O</c>
            <c>P</c>
      </set>
      <set select="Q">
            <c>Q</c>
            <c>R</c>
            <c>S</c>
            <c>T</c>
            <c>U</c>
            <c>V</c>
            <c>W</c>
            <c>X</c>
            <c>Y</c>
            <c>Z</c>
      </set>
</sets>
0
 
LVL 13

Expert Comment

by:R7AF
ID: 19582658
<xsl:for-each select="Content[substring(Title,1,1)=$sets/set[@select='Q']/c]">

Btw, I see I that I hard coded 'Q', but of course you can use another selector here. You could include a parameter in your XML, and use that. Notice that I used an extra variable ($filter).

<Collection>
      <params>
            <filter>Q</filter>
      </params>
      <Content>
             ..............
       </Content>
</Collection>

#################### XSLT ####################

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
            version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:msxsl="urn:schemas-microsoft-com:xslt"
            exclude-result-prefixes="msxsl">
            
      <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
      
      <xsl:template match="Collection">
            <xsl:variable name="sets" select="document('first.xml')/sets"/>
            <xsl:variable name="filter" select="params/filter"/>
            <div align="center">test
                  <table cellspacing="3" border="1px" cellpadding="3" width="700px">
                        <xsl:for-each select="Content[substring(Title,1,1)=$sets/set[@select=$filter]/c]">
                              <xsl:sort select="Html/root/Name" />
                              <tr>
                                    <td valign="top" align="left">
                                          <xsl:value-of select="Title" />
                                    </td>
                                    <td valign="top" align="left">
                                          <xsl:if test="Html/root/email">
                                                <a href="mailto:{Html/root/email}">
                                                      <xsl:value-of select="Html/root/email" />
                                                </a>
                                          </xsl:if>
                                    </td>
                              </tr>
                        </xsl:for-each>
                  </table>
            </div>
      </xsl:template>

</xsl:stylesheet>
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question