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

Excluding records from a search

Subject: Excluding records from a search
From: "Lewis, Russell" <Russell.Lewis@xxxxxxxxxxxxxxxx>
Date: Mon, 3 Mar 2008 16:25:16 -0500
 Excluding records from a search
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

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.