[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

Run a like search in XSL/XPATH

Asked by jay_eire in JavaScript, Extensible Markup Language (XML), XPath

Hi Guys,
I have a HTML form that is that is searching an XML file based on artist name, instead of searching just the artist name i want to direct my search to the <keyword></keyword> node instead, this way i can add in more search keyword terms for each artist, is it possible to do a 'like search ' in XSL/XPATH as in SQL you would do "%searchterm%", for example if the user entered in a 'country music' it would look through all the words in my<Keyword>Bonnie Tyler, Hide Your Heart, Greatest hits, discography, country music, Goodbye to the Island, 80s </Keyword> nodes for each artist and return back any matches it found. Ive attached my code snippets
Thanks
Jay

Thanks
Jay
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
******************
Search Form
******************
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    
 
</head>
<body>
  <form action="page2.html">
        Find <input type="text" NAME="q" />
        <input type="submit" value="Go" />
</form>
</body>
</html>
 
******************
Page2.html
******************
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <script type="text/javascript">
        var xmlDoc;
        var xslt;
        
        function BuildResult() {           
            //code for Internet Explorer
            if (window.ActiveXObject) {
                xslt = new ActiveXObject("Msxml2.XSLTemplate");
                var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
 
                xslDoc.async = false;
                xslDoc.resolveExternals = false;
                xslDoc.load("cdcatalog.xsl");
                xslt.stylesheet = xslDoc;
                
                xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
                xmlDoc.async = false;
                xmlDoc.resolveExternals = false;
                xmlDoc.load("cdcatalog.xml");
                
                displayResult();
            }
            // code for Mozilla, Firefox, Opera, etc.
            else if (document.implementation && document.implementation.createDocument) {
                objXml = document.implementation.createDocument("", "", null);
                objXml.load("cdcatalog.xml");
 
                objXsl = document.implementation.createDocument("", "", null);
                objXsl.load("cdcatalog.xsl");
 
                objXsl.onload = displayResult;
            }
 
        }
        function displayResult() {
          var artistname = unescape(location.search.substring(3)); // skip ?q=  
 
            if (window.ActiveXObject) {
                var xslProc = xslt.createProcessor();
                xslProc.input = xmlDoc;
                xslProc.addParameter("artistname", artistname);
                xslProc.transform();
                document.getElementById('divResult').innerHTML = xslProc.output;
            }
            else {
                var processor = new XSLTProcessor();
                processor.importStylesheet(objXsl);
 
                processor.setParameter(null, "artistname", artistname);
                
                var trandoc = processor.transformToFragment(objXml, document);
                document.getElementById('divResult').innerHTML = "";
                document.getElementById('divResult').appendChild(trandoc);
            }            
        }
window.onload=function() {
 BuildResult()
}
    </script>
 
</head>
<body>
   
 
     <div id="divResult"> </div>    
</body>
</html>
 
******************
cdcatalog.xml
******************
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<!-- Edited by XMLSpy® -->
<catalog>
  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
    <link>www.google.com</link>
    <Keyword>bob dylan, Baby Let Me Follow You Down, Clothes Line Saga, discography, country music</Keyword>
  </cd>
  <cd>
    <title>Hide your heart</title>
    <artist>Bonnie Tyler</artist>
    <country>UK</country>
    <company>CBS Records</company>
    <price>9.90</price>
    <year>1988</year>
    <link>www.yahoo.com</link>
    <Keyword>Bonnie Tyler, Hide Your Heart, Greatest hits, discography, country music, Goodbye to the Island, 80s </Keyword>
  </cd>
  <cd>
    <title>Greatest Hits</title>
    <artist>Dolly Parton</artist>
    <country>USA</country>
    <company>RCA</company>
    <price>9.90</price>
    <year>1982</year>
    <link>www.bing.com</link>
    <Keyword>Dolly Parton, discography, texas,</Keyword>
  </cd>
</catalog>
******************
cdcatalog.xsl
******************
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:param name="artistname">bob dylan</xsl:param>
  <xsl:variable name="lc">
    <xsl:text>abcdefghijklmnopqrstuvwxyz+ </xsl:text>
  </xsl:variable>
  <xsl:variable name="uc">
    <xsl:text>ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:text>
  </xsl:variable>
  <xsl:template match="/">
    <html>
      <body>
        <h2>My CD Collection</h2>
        <table border="1">
          <tr bgcolor="#9acd32">
            <th>Title</th>
            <th>Artist</th>
 
          </tr>
          <xsl:for-each select="catalog/cd[translate(artist, $lc, $uc)= translate($artistname, $lc, $uc)]">
            <tr>
              <td>
                <xsl:value-of select="title"/>
              </td>
              <td>
                <xsl:value-of select="artist"/>
              </td>
            </tr>
          </xsl:for-each>
          <xsl:if test="not(catalog/cd[translate(artist, $lc, $uc)= translate($artistname, $lc, $uc)])">
            <tr bgcolor="red">
              <td colspan="2">No Results Found</td>
            </tr>
          </xsl:if>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
[+][-]06/16/09 11:39 AM, ID: 24640935Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: JavaScript, Extensible Markup Language (XML), XPath
Sign Up Now!
Solution Provided By: abel
Participating Experts: 1
Solution Grade: A
 
[+][-]06/16/09 11:47 AM, ID: 24641032Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/16/09 11:53 AM, ID: 24641096Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/16/09 12:02 PM, ID: 24641199Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/16/09 12:30 PM, ID: 24641582Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625