Jump to content

Retaining Capitalization


awitt

Recommended Posts

Hello All! So, I need some help on a familiar project. It's that darn XSLT I was having problems with that while ago. Everything is pretty much finished on it, but there are a couple rather persistent bugs that I cannot seem to work out on my own.1.) Retaining capitalization. -- If you look at the search() function, you can see why it won't keep the capital letters where they should be; I'm basing my replacement string on the characters typed into the input box. How can I recognize a capital letter and keep it in its appropriate spot within the replacement string?2.) Also, when transforming against the XML document, there are other problems sometimes. -- For example, sometimes the XML contains duplicate records (even with the same unique id). Now, I cannot control that - the XML is maintained by some kind of state database or something like that, so I can't alter it - I have to handle that. So, it comes into play when people are using the search or filter functionality. If the duplicate records aren't matches for whatever search, the program will hide the first instance of that duplicate record, but not the second instance. That means that although a user may have searched for "ohio," there's a result displaying that's something like "Wood County Allen High School." So, I need a way to handle duplicate records, should they occur.I've posted the whole program here for reference's sake. Also, I've included a snippet of the XML against which I would be transforming, complete with a duplicate record and everything!

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	<xsl:output method="html" version="1.0"/>	<xsl:template match="/">			<script type="text/javascript">			var visibleRow="table-row";		</script>				<xsl:comment>[if IE]>			<script type="text/javascript">				visibleRow="block";			</script>			<![endif]</xsl:comment>	   		<script type="text/javascript">			var table_for_sc=new Array();			var hidden_rows=new Array();			var tabletext="";			var delayExecution = false;			var processing = false;						function closing(id, co, lo, st)			{				this.ID=id				this.County=co;				this.Location=lo;				this.Status=st;			}						function create_array()			{   					var i=0;								<xsl:for-each select="closings/county/announcement">					var closing1=new closing("<xsl:value-of select="./@id" />", "<xsl:value-of select="../@name" />", 						"<xsl:value-of select="location" />", "<xsl:value-of select="status" />");					table_for_sc[i]=closing1;					i++;				</xsl:for-each>			}						function all()			{				for (var i=0; i < table_for_sc.length; i++)				{					var current_id="row_" + table_for_sc[i].ID;					document.getElementById(current_id).style.display = visibleRow;				}			}						function process()			{				if (processing == false)				{					window.setTimeout('search()', 250);					processing = true;										document.getElementById("closings-div").style.display = "none";					document.getElementById("loading_pic").style.display = "block";				}				else				{delayExecution = true;}			}						function search()			{				if (delayExecution == true)				{					delayExecution = false;					window.setTimeout('search()', 250);					return;				}								document.getElementById("closings-div").style.display = "block";				document.getElementById("loading_pic").style.display = "none";								if (hidden_rows.length > 0)				{					for (var i=0; i < hidden_rows.length; i++)					{document.getElementById(hidden_rows[i]).style.display = visibleRow;}										hidden_rows = new Array();				}								processing = false;				var counter=0;				var word111=document.getElementById("search_text").value;				var search_for_this=new RegExp (word111, "gi");				var span_tags_to_remove=new RegExp ("<xsl:text></span>|<span></xsl:text>","gi");				var replaceterm='<span>' + word111 + '</span>';								for (var zz=0; zz < table_for_sc.length; zz++)				{					var to_search=table_for_sc[zz].Location;					var current_id="row_" + table_for_sc[zz].ID;					to_search = to_search.replace(span_tags_to_remove, "");										if (search_for_this != "")					{to_search=to_search.replace(search_for_this, replaceterm);}										document.getElementById(current_id + "_loc").innerHTML=to_search;										if( !(to_search.match("<span>")) )					{						document.getElementById(current_id).style.display="none";						hidden_rows[counter]=current_id;						counter++;					}				}								var span_coll=document.getElementsByTagName("span");								if ( (span_coll.length == 0) && (word111.length > 0) )				{					document.getElementById("search_text").style.backgroundColor="red";					document.getElementById("search_text").value=document.getElementById("search_text").value.substring(0, word111.length-1);				}				else if (document.getElementById("search_text").style.backgroundColor="red")				{document.getElementById("search_text").style.backgroundColor="white";}			}						function filter()			{				var sort_by_value=document.getElementById("sort_by_for_sc").value;							if (sort_by_value != 0)				{					if (sort_by_value == 1)					{						all();									for (var x=0; x < table_for_sc.length; x++)						{							if ( !(table_for_sc[x].Status.match("closed")) && !(table_for_sc[x].Status.match("Closed")) )							{								var current_id="row_" + table_for_sc[x].ID;								document.getElementById(current_id).style.display="none";							}						}					}					else if (sort_by_value == 2)					{						all();									for (var x=0; x < table_for_sc.length; x++)						{							if ( !(table_for_sc[x].Status.match("emergency")) && !(table_for_sc[x].Status.match("Emergency")) )							{								var current_id="row_" + table_for_sc[x].ID;								document.getElementById(current_id).style.display="none";							}						}					}					else if (sort_by_value == 3)					{						all();									for (var x=0; x < table_for_sc.length; x++)						{							if ( !(table_for_sc[x].Status.match("delay")) && !(table_for_sc[x].Status.match("Delay")) )							{								var current_id="row_" + table_for_sc[x].ID;								document.getElementById(current_id).style.display="none";							}						}					}					else if (sort_by_value == 4)					{						all();									for (var x=0; x < table_for_sc.length; x++)						{							if ( (table_for_sc[x].Status.match("close"))     || 								 (table_for_sc[x].Status.match("delay"))     || 								 (table_for_sc[x].Status.match("emergency")) || 								 (table_for_sc[x].Status.match("Close"))     ||								 (table_for_sc[x].Status.match("Delay"))     || 								 (table_for_sc[x].Status.match("Emergency"))  )							{								var current_id="row_" + table_for_sc[x].ID;								document.getElementById(current_id).style.display="none";							}						}					}					else if (sort_by_value == 5)					{all();}					else if (sort_by_value == 6)					{						all();									for (var x=0; x < table_for_sc.length; x++)						{							if ( !(table_for_sc[x].County == "Franklin") && !(table_for_sc[x].County == "franklin") )							{								var current_id="row_" + table_for_sc[x].ID;								document.getElementById(current_id).style.display="none";							}						}					}					else if (sort_by_value == 7)					{						all();												for (var x=0; x < table_for_sc.length; x++)						{							if ( !(table_for_sc[x].County == "Delaware") && !(table_for_sc[x].County == "delaware") )							{								var current_id="row_" + table_for_sc[x].ID;								document.getElementById(current_id).style.display="none";							}						}					}					else if (sort_by_value == 8)					{						all();												for (var x=0; x < table_for_sc.length; x++)						{							if ( (table_for_sc[x].County.match("franklin")) || 								 (table_for_sc[x].County.match("delaware")) || 								 (table_for_sc[x].County.match("Franklin")) || 								 (table_for_sc[x].County.match("Delaware"))  )							{								var current_id="row_" + table_for_sc[x].ID;								document.getElementById(current_id).style.display="none";							}						}					}				}			}   		</script>			   	<title>State of Ohio Closings / Delays / Emergencies</title>	   	   		<h1>School Closings</h1>   		<div class="closings-search">            <p>enter a school or a business name to help limit search results:</p>			<input type="text" id="search_text" onkeyup="process()" value="" />            <h3>choose a subcategory to help limit the search results:</h3>			<select id="sort_by_for_sc" onchange="filter()">				<option value="5">-- All Listings --</option>				<optgroup label="STATUS">					<option value="1">Closed Schools</option>					<option value="2">Snow Emergencies</option>					<option value="3">Delays</option>					<option value="4">Any Other Status</option>				</optgroup>				<optgroup label="LOCATION">					<option value="6">Franklin County</option>					<option value="7">Delaware County</option>					<option value="8">Any Other Location</option>				</optgroup>			</select>	   		<script type="text/javascript">create_array();</script>   		</div>   		   		<div id="loading_pic" style="display: none;">   			<img src="loading1.gif" alt="working...please wait" />   		</div>   		   		<div id="closings-div">	   		<table id="results_table" class="closings-table">	   			<tr>	   				<th>COUNTY</th>	   				<th>LOCATION</th>	   				<th>STATUS</th>	   			</tr>	   			<xsl:for-each select="closings/county/announcement">				<tr>					<xsl:attribute name="id">row_<xsl:value-of select="./@id" /></xsl:attribute>					<td class="county_row">						<xsl:value-of select="../@name" />					</td>					<td class="location_row">						<xsl:attribute name="id">row_<xsl:value-of select="./@id" />_loc</xsl:attribute>						<xsl:value-of select="location" />					</td>					<td class="status_row">						<xsl:value-of select="status" />					</td>				</tr>	   			</xsl:for-each>	   		</table>	   	</div>	</xsl:template></xsl:stylesheet>

<closings> 	<county name="Adams"> 		<announcement id="1" onn="1" wbns="0"> 			<location>Ohio Valley Local Schools</location> 			<status>Closed</status> 			<source>172.19.16.33</source> 			<creationtime>Jan 28 2009 05:02AM</creationtime> 			<expiretime>Jan 28 2009 01:00PM</expiretime> 		</announcement> 		<announcement id="2443" onn="1" wbns="0"> 			<location>Snow Emergency</location> 			<status>Level 3 Snow Emergency</status> 			<source>172.19.16.33</source> 			<creationtime>Jan 28 2009 09:19AM</creationtime> 			<expiretime>Jan 28 2009 07:00PM</expiretime> 		</announcement> 	</county> 	<county name="Allen"> 		<announcement id="6" onn="1" wbns="0"> 			<location>Elida Local Schools</location> 			<status>Closed</status> 			<source>4193314115</source> 			<creationtime>Jan 28 2009 05:40AM</creationtime> 			<expiretime>Jan 28 2009 01:00PM</expiretime> 		</announcement> 		<announcement id="3538" onn="1" wbns="0"> 			<location>Snow Emergency</location> 			<status>Level 1 Snow Emergency</status> 			<source>172.19.16.8</source> 			<creationtime>Jan 28 2009 09:15AM</creationtime> 			<expiretime>Jan 28 2009 07:00PM</expiretime> 		</announcement> 	</county>	<county name="Wood"> 		<announcement id="602" onn="1" wbns="0"> 			<location>Bowling Green City Schools</location> 			<status>Closed</status> 			<source>172.19.16.8</source> 			<creationtime>Jan 28 2009 06:50AM</creationtime> 			<expiretime>Jan 28 2009 01:00PM</expiretime> 		</announcement> 		<announcement id="603" onn="1" wbns="0"> 			<location>Eastwood Local Schools</location> 			<status>Closed</status> 			<source>172.19.16.8</source> 			<creationtime>Jan 28 2009 06:53AM</creationtime> 			<expiretime>Jan 28 2009 01:00PM</expiretime> 		</announcement> 		<announcement id="603" onn="1" wbns="0"> 			<location>Eastwood Local Schools</location> 			<status>Closed</status> 			<source>172.19.16.8</source> 			<creationtime>Jan 28 2009 06:53AM</creationtime> 			<expiretime>Jan 28 2009 01:00PM</expiretime> 		</announcement> 	</county></closings>

Link to comment
Share on other sites

1.) Retaining capitalization.
In order to fix that, instead of replacing the text with the text they typed, you'll need to find the match and replace it with itself, with a span tag around it.I'm not sure about the duplicates though.
Link to comment
Share on other sites

In order to fix that, instead of replacing the text with the text they typed, you'll need to find the match and replace it with itself, with a span tag around it.I'm not sure about the duplicates though.
Yea, I know I have to find the match. I tried doing that against the array that I created, but it acted kind of randomly. I since deleted that code, but give me til later today, or sometime tomorrow, and I'll recreate it and let you take a look at it. I know how and what to do (in my head, that is), but it's one of those lil problems that are more difficult to solve than you'd think. And darn those duplicates, they're makin' me erngry!
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...