[xsl] Excluding records from a search

Subject: [xsl] Excluding records from a search
From: "Lewis, Russell" <Russell.Lewis@xxxxxxxxxxxxxxxx>
Date: Mon, 3 Mar 2008 16:25:16 -0500
After a relaxing weekend I realized that what I posted earlier probably made
no sense so here it goes again only this time it's a little more
understandable I hope:
This works:
1) If the user searches for "entry" ($searchtext = "entry") the output should
also include the fourth and fifth record because Field1 contains "all", "All",
or "ALL" even though the fourth record doesn't contain any case of "entry".
Also the fifth record should only be output once even though it contains any
case of "all" in Field1 and also any case of "entry" in Field2. I've managed
to accomplish this using this statement:
 <xsl:for-each select="record[*[name() = $searchfield][contains(.,
$ProperText) or contains(., $UCASETEXT) or contains(., $lcasetext) or
../Field1[contains(., 'ALL') or contains(., 'all') or contains(., 'All')]]]">
I can't make this work though:
 2) But I want the output of this same search to ALSO exclude the second and
sixth record because Field1 contains "info", "Info" or "INFO" even though
Field2 contains "Entry", "entry", or "ENTRY". The info records won't be viewed
using this stylesheet. The records where Field1 contains any case of "info"
will only show up when you use a different stylesheet much like this one in
which case it will be treated just like this stylesheet treats records where
Field1 is "all".
XML Data
<?xml version="1.0"?>
<data>
  <record>
    <Field1>Data1-1</Field1>
    <Field2>Entry1-2</Field2>
    <dtmField>2008-01-28T01:01:00Z</dtmField>
  </record>
  <record>
    <Field1>Info</Field1>
    <Field2>This entry is not readable</Field2>
    <dtmField>2008-01-28T02:02:00Z</dtmField>
  </record>
  <record>
    <Field1>Data3-1</Field1>
    <Field2>Entry3-2</Field2>
    <dtmField>2008-01-28T03:03:00Z</dtmField>
  </record>
  <record>
    <Field1>all</Field1>
    <Field2>This record is readable by everyone</Field2>
    <dtmField>2008-01-28T04:04:00Z</dtmField>
  </record>
  <record>
    <Field1>All</Field1>
    <Field2>This entry is also readable by everyone</Field2>
    <dtmField>2008-01-28T05:05:00Z</dtmField>
  </record>
  <record>
    <Field1>info</Field1>
    <Field2>This entry is also not readable</Field2>
    <dtmField>2008-01-28T06:06:00Z</dtmField>
  </record>
</data>
<!-- Desired output -->
  <record>
    <Field1>Data1-1</Field1>
    <Field2>Entry1-2</Field2>
    <dtmField>2008-01-28T01:01:00Z</dtmField>
  </record>
Record 2 is excluded because Field1 = "Info"
  <record>
    <Field1>Data3-1</Field1>
    <Field2>Entry3-2</Field2>
    <dtmField>2008-01-28T03:03:00Z</dtmField>
  </record>
  <record>
    <Field1>all</Field1>
    <Field2>This entry is readable by everyone</Field2>
    <dtmField>2008-01-28T04:04:00Z</dtmField>
  </record>
Record 5 below is included only once even though Field2 contains "entry" AND
Field1 contains "all"
  <record>
    <Field1>All</Field1>
    <Field2>This entry is also readable by everyone</Field2>
    <dtmField>2008-01-28T05:05:00Z</dtmField>
  </record>
Record 6 is excluded because "Field1" = info even though Field2 contains
"entry"
XSL Stylesheet
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
  <xsl:output method="html"/>
  <xsl:param name="searchfield" select="Field2"/>
  <xsl:param name="searchtext" select="entry"/>
  <xsl:param name="sortbyfield" select="Field1"/>
  <xsl:param name="sortorder" select="Descending"/>
  <xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
  <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
  <xsl:variable name="lcasetext" select="translate($searchtext, $uppercase,
$lowercase)"/>
  <xsl:variable name="UCASETEXT" select="translate($searchtext, $lowercase,
$uppercase)"/>
  <xsl:variable name="ProperText"
select="concat(translate(substring($searchtext,1,1), $lowercase,
$uppercase),translate(substring($searchtext,2), $uppercase, $lowercase))"/>
  <xsl:template match="data">
    <html xmlns="http://www.w3.org/1999/xhtml";>
      <head>
        <title> Search Results </title>
      </head>
      <body>
        <p class="title"> Search Results </p>
        <table>
          <tr>
            <th> Field1 </th>
            <th> Field2 </th>
            <th> Date &amp; Time</th>
          </tr>
          <xsl:for-each select="record[*[name() = $searchfield][contains(.,
$ProperText) or contains(., $UCASETEXT) or contains(., $lcasetext) or
../Field1[contains(., 'ALL') or contains(., 'all') or contains(., 'All')]]]">
          <xsl:sort select="*[name()=$sortbyfield]" order="{$sortorder}"/>
            <tr>
              <td>
                 <xsl:value-of select="Field1"/>
              </td>
              <td>
                  <xsl:value-of select="Field2"/>
              </td>
              <td>
                  <xsl:value-of select="dtmField"/>
              </td>
             </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

Current Thread