xsl-list
[Top] [All Lists]

[xsl] Translate then sort

2008-01-18 07:40:33
This is more of a program flow problem than an XSLT problem but it might have 
an XSL solution that I haven't discovered.
This stylesheet has an external ASP program that sends the $searchfield, 
$sortby, $searchtext, and $search-by-number parameters from another stylesheet. 
The $searchtext parameter is translated by "variable" statements (not shown) 
into $ProperText, $UCASETEXT, and $lcasetext.
The first two sort/search templates are called by the last template and send 
their output to the "resulttable" template.
The problem I have is the sort is executed after each "for-each" search in the 
"searchrecords" template and if records are located by one of the subsequent 
"for-each" searches then the search output is not sorted as a whole.
How can I create an all inclusive routine that will perform one search for all 
the records found by all three "for-each" routines in the "searchrecords" 
template? Or is there a better way to perform my case translation in XSLT 1.0?
-
XML File Structure: 
(Data is purposely out of order to test the "numbersearch" template sort)
<allrecords>
 <record>
  <field1>DATA 1</field1>
  <field2>Data 3</field2>
  <field3>data 2</field3>
  <field4>Data 4</field4>
 </record>
</allrecords>
-
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"> 
   
 <xsl:output method="html"/>
  <xsl:template name="searchrecords">
      <xsl:for-each select="record[*[name() = $searchfield][contains(., 
$ProperText)]]">
    <xsl:sort select="*[name()=$sortby]" order="ascending" />
    <xsl:call-template name="resulttable"/>
   </xsl:for-each>
      <xsl:for-each select="record[*[name() = $searchfield][contains(., 
$UCASETEXT)]]">
    <xsl:sort select="*[name()=$sortby]" order="ascending" />
    <xsl:call-template name="resulttable"/>
   </xsl:for-each>
      <xsl:for-each select="record[*[name() = $searchfield][contains(., 
$lcasetext)]]">
    <xsl:sort select="*[name()=$sortby]" order="ascending" />
    <xsl:call-template name="resulttable"/>
    </xsl:for-each>
  </xsl:template>
-
  <xsl:template name="numbersearch">
      <xsl:for-each select="record[*[name() = $searchfield][contains(., 
$searchtext)]]">
    <xsl:sort select="*[name()=$sortby]" order="ascending" />
    <xsl:call-template name="resulttable"/>
   </xsl:for-each>
  </xsl:template>
-
  <xsl:template name="resulttable">
     <tr>
        <td><xsl:value-of select="field1"/></td>
        <td><xsl:value-of select="field2"/></td>
        <td><xsl:value-of select="field3"/></td>
        <td><xsl:value-of select="field4"/></td>
      </tr>
  </xsl:template>
-
   <xsl:template match="allrecords">
     <html xmlns="http://www.w3.org/1999/xhtml";>
    <!-- HTML to format page and table headers goes here -->
        <xsl:if test="$search-by-number = 0">
         <xsl:call-template name="searchrecords"/>
        </xsl:if>
        <xsl:if test="$search-by-number = 1">
         <xsl:call-template name="numbersearch"/>
        </xsl:if>
    </html>
  </xsl:template>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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