Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 29th, 2008, 10:41 AM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Including some records and excluding others

I'm trying to learn how/do two things here:
1) If the user searches for "Data" ($searchtext = "Data") the output should also include the fourth record because Field1 contains "all".
 2) But the output of this same search should also exclude any records where Field1 contains "info" ($searchtext = "info"). You can see by the textsearch template that I have 3 case conversion variables that can be used to to include/exclude "All", "all", "ALL", "Info", "info", or "INFO"

A statement like this includes "all" but I can't figure out how to get it to also exclude "info" or use my case variables:
 <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')]]]">

XML Data

<?xml version="1.0"?>
<data>
  <record>
    <Field1>Data1-1</Field1>
    <Field2>Data1-2</Field2>
    <dtmField>2008-01-28T01:01:00Z</dtmField>
  </record>
  <record>
    <Field1>Info</Field1>
    <Field2>Data2-2</Field2>
    <dtmField>2008-01-28T02:02:00Z</dtmField>
  </record>
  <record>
    <Field1>Data3-1</Field1>
    <Field2>Data3-2</Field2>
    <dtmField>2008-01-28T03:03:00Z</dtmField>
  </record>
  <record>
    <Field1>all</Field1>
    <Field2>Data4-2</Field2>
    <dtmField>2008-01-28T04:04:00Z</dtmField>
  </record>
  <record>
    <Field1>All</Field1>
    <Field2>Data5-2</Field2>
    <dtmField>2008-01-28T05:05:00Z</dtmField>
  </record>
  <record>
    <Field1>info</Field1>
    <Field2>Data6-2</Field2>
    <dtmField>2008-01-28T06:06:00Z</dtmField>
  </record>
</data>


<?xml version="1.0"?>
<data>
  <record>
    <Field1>Data1-1</Field1>
    <Field2>Data1-2</Field2>
    <dtmField>2008-01-28T01:01:00Z</dtmField>
  </record>
Record 2 is excluded because "Field1" = Info
  <record>
    <Field1>Data3-1</Field1>
    <Field2>Data3-2</Field2>
    <dtmField>2008-01-28T03:03:00Z</dtmField>
  </record>
  <record>
    <Field1>all</Field1>
    <Field2>Data4-2</Field2>
    <dtmField>2008-01-28T04:04:00Z</dtmField>
  </record>
  <record>
    <Field1>All</Field1>
    <Field2>Data5-2</Field2>
    <dtmField>2008-01-28T05:05:00Z</dtmField>
  </record>
Record 6 is excluded because "Field1" = info (notice the case is different)
</data>

XSL Stylesheet

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="html"/>

<!--
The "selected" value of thes parameters are filled in for this example. Normally they are passed from an external ASP VBScript that processes inputs from another form where the values are input by the user.
-->
  <xsl:param name="searchfield" select="Field1"/>
  <xsl:param name="searchtext" select="Data"/>
  <xsl:param name="sortbyfield" select="Field2"/>
  <xsl:param name="sortorder" select="Descending"/>

  <xsl:template name="textsearch">
    <xsl:for-each select="record[*[name() = $searchfield][contains(., $ProperText) or contains(., $UCASETEXT) or contains(., $lcasetext)]]">
      <xsl:sort select="*[name()=$sortbyfield]" order="{$sortorder}"/>
      <xsl:call-template name="resulttable"/>
    </xsl:for-each>
  </xsl:template>



Reply With Quote
  #2 (permalink)  
Old February 29th, 2008, 10:57 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Unfortunately in XSLT 1.0 the easiest way to check things while ignoring case is to use the translate() function.

e.g. translate(., "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz") will convert the current text to lower case.

In XSLT 2.0 you can use the lower-case() function.

<xsl:template name="textsearch">
    <xsl:variable name="data">
      <xsl:value-of select="translate($searchdata, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")"/>
    </xsl:variable>
    <xsl:for-each select="record[*[name() = $searchfield and contains(translate(., "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"), $data)]]">
      <xsl:sort select="*[name()=$sortbyfield]" order="{$sortorder}"/>
      <xsl:call-template name="resulttable"/>
    </xsl:for-each>
  </xsl:template>

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #3 (permalink)  
Old March 3rd, 2008, 12:36 PM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your response Sam but after getting some much needed rest over the weekend and after looking over my question again I realized that I misworded my question. I'll re-ask it under the topic "Excluding certain records from a search".

Thanks,
Russ Lewis

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excluding certain records from a search RussLewis XSLT 5 March 4th, 2008 12:14 PM
Excluding Rows fs22 SQL Language 2 August 17th, 2005 12:58 PM
excluding archives of a folder thomaz C# 4 March 8th, 2004 09:09 AM
excluding html from printer .. qwjunk Classic ASP Basics 1 February 3rd, 2004 04:09 PM
Excluding items with certain keywords ashcarrot SQL Language 4 July 23rd, 2003 10:04 AM



All times are GMT -4. The time now is 08:09 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.