Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 12th, 2003, 12:17 AM
Registered User
 
Join Date: Nov 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT keyword search help

Hi, I am fiarly new to this and have run into a dead end with performin this keyword search. Either I get all the wrong results or none of them. Can anybody set me on a path to figuring this out??

------XML---------
<?xml version="1.0" encoding="UTF-8" ?>
<FMPDSORESULT xmlns="http://www.filemaker.com/fmpdsoresult">

<ROW MODID="6" RECORDID="42"><book_author>Adam Ross</book_author>
<book_name>Waldo Rules the World</book_name>
</ROW>


<ROW MODID="0" RECORDID="47"><book_author>Johns Hopkins</book_author>
<book_name>Medical Dictionary</book_name>
</ROW>


---xsl---

<?xml version='1.0' encoding='iso-8859-1'?>

<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:output method='html' version='1.0' encoding='iso-8859-1' indent='no'/>
    <xsl:param name="upperCase" select="ABCDEFGHIJKLMNOPQRSTUVWXYZ"/>
    <xsl:param name="lowerCase" select="abcdefghijklmnopqrstuvwxyz"/>
    <xsl:param name="searchTextToTranslate" select="Waldo"/>
    <xsl:param name="translatedSearchText"
    select="translate($searchTextToTranslate, $upperCase, $lowerCase)"/>

<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>

<xsl:template match="//ROW">
<xsl:apply-templates />
<xsl:for-each select="book_name">
    <xsl:if test="contains(translate(book_name, $upperCase, $lowerCase),
$translatedSearchText)">
        <xsl:value-of select="book_author"/><br/>
     </xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


----------

I receive no errors, just all the xml document

 
Old November 12th, 2003, 05:00 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You don't have any ROW elements, you have {http://www.filemaker.com/fmpdsoresult}:ROW elements so you need to use this namespace when searching. Add the namespace URI to the stylesheet element and give it an arbitrary prefix:
Code:
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
 xmlns:default='http://www.filemaker.com/fmpdsoresult'>
Then to search use:
Code:
//default:ROW
You also don't need the for-each or the apply-templates after it. Your search term is an element called 'Waldo', what you need is the text 'Waldo' so you must enclose it in quotes, presumably you'll be passing this in to the stylesheet in normal use. Personally I'd use a variable for the translated term. The first template matching root is also unnecessaary as your match of //default:ROW will catch all ROW elements in default namespace. A simple version of your stylesheet would be:
Code:
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
 xmlns:default='http://www.filemaker.com/fmpdsoresult'
 exclude-result-prefixes="default">

<xsl:output method='html' version='1.0' encoding='iso-8859-1' indent='no'/>
  <xsl:param name="upperCase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
  <xsl:param name="lowerCase" select="'abcdefghijklmnopqrstuvwxyz'"/>
  <xsl:param name="searchTextToTranslate" select="'Waldo'"/>
  <xsl:variable name="translatedSearchText" select="translate($searchTextToTranslate, $upperCase, $lowerCase)"/>
  
  <xsl:template match="//default:ROW">
    <xsl:if test="contains(translate(default:book_name, $upperCase, $lowerCase), $translatedSearchText)">
          <xsl:value-of select="default:book_author"/><br/>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>
Joe (MVP - xml)
 
Old November 12th, 2003, 08:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

Note that you have to write
Code:
    <xsl:param name="upperCase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
    <xsl:param name="lowerCase" select="'abcdefghijklmnopqrstuvwxyz'"/>
instead(embrace with apostrophes to denote that the variables contain strings; otherwise you'll get empty nodesets as values of $upperCase and $lowerCase, since there are no matching nodes with those element types).

Regards,
Armen





Similar Threads
Thread Thread Starter Forum Replies Last Post
Search by Keyword Grafixx01 Access 10 May 31st, 2007 08:59 AM
Want to Search Several Fields for the Same Keyword Eyrehead Access 3 March 16th, 2007 11:08 AM
Keyword search Echo10 Excel VBA 3 April 23rd, 2006 08:10 AM
Multiple Keyword Search tuffour Classic ASP Databases 3 September 10th, 2004 06:12 AM
highlighting the search keyword(s) Adam H-W Classic ASP Basics 2 February 10th, 2004 09:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.