#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep 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&amp;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?
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,238
    Rep Power
    9400
    XSLT is not a search engine. If you want one then use something else.

    For the alphanumeric problem, put quotes around the search term.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep 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:


    $(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?

IMN logo majestic logo threadwatch logo seochat tools logo