XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 6th, 2012, 11:30 AM
Xmonster Xmonster is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 11 Xmonster User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 56 m 47 sec
Reputation Power: 0
Searching for text elements and inexact matches with XSL

I'm writing a basic XSL to search through a XML file that reads like this;

Code:
<cbo_list>
  <cbo>
    <cbo_id>25</cbo_id>
    <cbo_name>Alianza Dominicana, Inc.</cbo_name>
    <cbo_address>2410 Amsterdam Avenue, 4th Fl</cbo_address>
    <cbo_city>New York</cbo_city>
    <cbo_state>NY</cbo_state>
    <cbo_zip>10033</cbo_zip>
  </cbo>
  <cbo>
    <cbo_id>916</cbo_id>
    <cbo_name>Asociaciones Dominicanas, Inc</cbo_name>
    <cbo_address>202 Union Avenue, 2, L&M</cbo_address>
    <cbo_city>Brooklyn</cbo_city>
    <cbo_state>NY</cbo_state>
    <cbo_zip>11211</cbo_zip>
  </cbo>


The XSL is;

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>

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

<xsl:param name="CBO"/>

<xsl:template match="/">
<html>
<body>
  <h2>Results</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>ID#</th>
        <th>Name</th>
        <th>Address</th>
    <th>City</th>
    <th>State</th>
    <th>Zipcode</th>
  </tr>
  <xsl:for-each select="dycd_bridge/contracts_datastore/cbo_list/cbo[node()=$CBO]">

      <tr>
        <td><xsl:value-of select="cbo_id"/></td>
        <td><xsl:value-of select="cbo_name"/></td>
        <td><xsl:value-of select="cbo_address"/></td>
        <td><xsl:value-of select="cbo_city"/></td>
        <td><xsl:value-of select="cbo_state"/></td>
        <td><xsl:value-of select="cbo_zip"/></td>
      </tr>

 </xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>


Basically, the user searches via a standard HTML search box that then passes the parameters to the XSL. The problem is, the XSL will only return results if an exact match is found, and it won't even process the search if alphabetic characters are present. How do I fix this?

Reply With Quote
  #2  
Old November 6th, 2012, 12:38 PM
requinix's Avatar
requinix requinix is offline
Still alive
Dev Shed God 16th Plane (12500 - 12999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,869 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 5 Days 6 h 19 m 22 sec
Reputation Power: 8977
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
XSLT is not a search engine. If you want one then use something else.

For the alphanumeric problem, put quotes around the search term.

Reply With Quote
  #3  
Old November 10th, 2012, 01:45 AM
Xmonster Xmonster is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 11 Xmonster User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 56 m 47 sec
Reputation Power: 0
Yeah, didn't think it'd be that easy. New idea; the page that, as of now, parses the XML into HTML format uses the following script:


Quote:
$(document).ready(function(){
$.ajax({
type: "GET",
url: "cbo_list.xml",
dataType: "xml",
success: function(xml) {
var Counter = 0;
$(xml).find('cbo').each(function(){

var cboID = $(this).find('cbo_id').text();
var cboName = $(this).find('cbo_name').text();
var cboAddress = $(this).find('cbo_address').text();
var cboCity = $(this).find('cbo_city').text();
var cboState = $(this).find('cbo_state').text();
var cboZip = $(this).find('cbo_zip').text();
var cboDisplayName = cboName;
if (cboName.length >= 30) {
cboDisplayName = cboName.substring(0, 30) + '...';
}



$('<div class="items" id="link_' + cboID +'"></div>').html('<a href="cboDetail.html?cboID=' + cboID + '">' + cboDisplayName + '</a>').appendTo('#page-wrap');
$('<div class="cboAddress"></div>').html(cboAddress).appendTo('#page-wrap');
$('<div class="cboAddress"></div>').html(cboCity + ', ' + cboState + '. ' + cboZip).appendTo('#page-wrap');
$('<hr>').html('<hr>').appendTo('#page-wrap');
//}
});
}
});
});

function SettingsForm() {
document.location = 'settings.html';
}


How best to edit this so that it displays the data based on user-defined variables?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Searching for text elements and inexact matches with XSL

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap