[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Translate then sort

Subject: Translate then sort
From: "Lewis, Russell" <Russell.Lewis@xxxxxxxxxxxxxxxx>
Date: Fri, 18 Jan 2008 09:39:56 -0500
 Translate then sort
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>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.