xsl-list
[Top] [All Lists]

Re: dynamic sort order

2003-07-31 06:38:07
Thanks J. Unfortunately, the LDAP server does not
sort. I wish it did! Would make life easier.

I get what you are doing in your XSLT, however, I do
not want to limit the sort order fields to only two.
If the end user developer (this is a web service)
wants to sort by name, employer, code and phone, I
want to allow it. This is why I was trying to use a
named template to loop over those elements.

Here are some more details for you. I appreciate your
help.

XML:
<searchResults>
  <searchResult>
        <uniqueID>HQ007267</uniqueID>
    <firstName>Jonathan</firstName>
    <lastName>Smith</lastName>
    <name>Jonathan H Smith</name>
    <title>Senior Consultant</title>
    <organization>National 
Aeronautics and Space Administration</organization>
        <orgUnit>headquarters</orgUnit>
    <email>jsmith5(_at_)mail(_dot_)hq(_dot_)nasa(_dot_)gov</email>
    <code>AO</code>
    <employer>Booz, Allen and Hamilton</employer>
    <phone>+1 202 358-1389</phone>
    <fax>+1 202 358-3063</fax>
    <building>HQ</building>
    <room>6075</room>
  </searchResult>
  <searchResult>
        <uniqueID>HQ005617</uniqueID>
        <firstName>Mark</firstName>
        <lastName>Smith</lastName>
        <name>Mark Allen Smith</name>
    <title>Criminal Investigator</title>
    <organization>National 
Aeronautics and Space Administration</organization>
        <orgUnit>headquarters</orgUnit>
    <email>mark(_dot_)smith(_at_)nasa(_dot_)gov</email>
    <code>W</code>
    <employer>NASA</employer>
    <phone>+1 818 354-9804</phone>
    <fax>+1 818 393-4271</fax>
    <building>JPL</building>
    <room></room>
  </searchResult>
  <supplementaryData>
    <sort>
      <sortField>employer</sortField>
      <sortField>lastName</sortField>
      <sortPage>search.cfm</sortPage>
    </sort>
    <display>
                  <displayField>name</displayField>
                  <displayField>employer</displayField>
                  <displayField>code</displayField>
                  <!--<displayField>room</displayField>-->
                  <displayField>phone</displayField>
          <displayField>email</displayField>
    </display>
   
<ldapBaseUrl>ldap://ldap.hq.nasa.gov:389/ou=headquarters,o=National

Aeronautics and Space
Administration,c=us??sub?</ldapBaseUrl>
  </supplementaryData>
</searchResults>

XSLT (relevant):
<xsl:template match="searchResults">
  <xsl:choose>
        <!-- there are some search results -->
        <xsl:when test="searchResult">
         <table width="100%" border="0"
summary="Search Result Output">
            <tr>
            <xsl:for-each
select="$displayFields/displayField">
            <xsl:variable name="dField">

             <xsl:call-template
name="ConvertProperCase">
                <xsl:with-param name="toconvert"
select="normalize-space(.)" />
             </xsl:call-template>
            </xsl:variable>
            <th align="left"><a
href="{$sortPage}?sort={$dField}"><xsl:value-of
select="$dField" /></a></th>
          </xsl:for-each>
           </tr>
           <tr> 
             <td colspan="5">&#160;</td>
           </tr>
           <xsl:apply-templates select="searchResult">
             <!-- set the sort -->
             <!-- cannot do this here!!! How to do it??
             <xsl:call-template name="sort" /> -->
           </xsl:apply-templates>
        </table>
     </xsl:when>
     <!-- there are no search results -->
     <xsl:otherwise>
        <p>Your search returned no results.</p>
     </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="sort">
  <xsl:for-each
select="/searchResults/supplementaryData/sort/sortField">
    <xsl:sort select="normalize-space(.)"/>
  </xsl:for-each>
</xsl:template>


--Nate


-----------------------------------------------------
Your approach is somewhat ... unorthodox. Why don't
you let
the LDAP server sort and filter? A few more details
about
your XML and the whole problem wouldn't have hurt
either.
I'll fill in any blanks, which may or may not have
something
to do with your question.

Anyway, assuming your XML is more complete as
  <whatever>
    <supplementaryData> ... </supplementaryData>
    <searchResults>
      <searchResult>
        <employer>foo</employer>
        ...
      </searchResult>
    </searchResults>
  </whatever>

then try
  <xsl:template match="whatever">
    <xsl:apply-templates
select="searchResults/searchResult>
      <xsl:sort
  
select="*[name()=current()/supplementaryData/sort/sortField[1]]"/>
      <xsl:sort
  
select="*[name()=current()/supplementaryData/sort/sortField[2]]"/>
   </xsl:apply-templates>
  </xsl:template>

Feel free to post your problem again with more details
if this
doesn't match it.

J.Pietschmann

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>