OFFLIST: [xsl] Re: XSLT to find missing characters?

Subject: OFFLIST: [xsl] Re: XSLT to find missing characters?
From: "Kirk Allen Evans" <kaevans@xxxxxxxxxxxxx>
Date: Sat, 13 Jul 2002 15:26:14 -0400
Thank you all for your suggestions.

As usual, the problem was only half-stated by the client.  So, here is a
curveball.  They want this to act kind of like a dynamic list box where they
can enter parts of a phrase.  Kind of like the index search in MSDN where
you type part of a phrase and it finds the next entry for you.  A more
precise requirement is that they want some kind of less-than or greater-than
operator for strings.

Given the corrected input XML (I had "Bud Lite" and "Budweiser" ordered
incorrectly):

<beers>
	<beer name="Amstel Light"/>
 	<beer name="Bud Lite"/>
 	<beer name="Budweiser"/>
 	<beer name="Buffalo Beer"/>
 	<beer name="Buzz Beer"/>
 	<beer name="Cool Creek"/>
 	<beer name="Cooper&apos;s Reserve"/>
 	<beer name="Coors"/>
 	<beer name="Michelob"/>
 	<beer name="Miller Lite"/>
 	<beer name="Sam Adams"/>
</beers>

The node list will be pre-sorted based on the name attribute.  They want to
enter "Bud" and get "Bud Lite", or "Budw" to get "Budweiser".  If no nodes
are found (like "Budx"), then the next node alphabetically is returned
("Buffalo Beer").  There is no limitation on the last match position in the
string.  For instance, when working with "Budx", the third character is
significant.  When working with "Cooq", the fourth character is significant
(and should return "Coors").  "Apqrstuvwxyz" makes the second character
significant and would return "Bud Lite".

Here is my first stab, modifying Dimitre's XPath solution with an additional
union:

(
	/*/*[starts-with(@name,$vStartPhrase)][1]
	|
	/*/*[contains(substring-after($vAlphabet, $vStartLetter),
			  substring(@name,1,1))][1]
)[1]

| /*/*[1][contains(substring-before($vAlphabet, $vStartLetter ),
			 substring(/*/*[last()]/@name,1,1))]


My change works, but has a flaw in that "Buffalo Beer" is not returned:
"Cool Creek" is.  I asked if it would be OK to get the last node that
matches the first 2 letters (ie, "Buzz Beer"), they said no:  the business
case says that it should return "Buffalo Beer".

I think I can conceive a solution using XSLT that uses the same recursive
approach as the original post.  But they want to implement this using a
single XPath statement in order to shove the solution into their existing
framework using MSXML and selectSingleNode.

Kirk


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread