[XSL-LIST Mailing List Archive Home]
Re: [xsl] Literal string question
Subject: Re: [xsl] Literal string question|
From: Trevor Nash <tcn@xxxxxxxxxxxxx>
Date: Fri, 28 Dec 2001 23:46:25 +0000
>I would like to select all names that have initials not seperated by
>a space. Such as:
>Could someone give me the syntax for searching for such a string?
You do not give enough detail to specify a precise algorithm. If you
are trying to clean up manual input then you are likely to want
something quite sophisticated, and as Wendell suggested that might be
easier in a language other than XSLT. But if you think carefully you
might be able to find a formula that fits what XSLT has to offer in
the way of string functions.
normalize-space() will remove leading and trailing white space, and
convert any other white space to a single space, so
" D. J. Smith "
"D. J. Smith"
Then, does your problem just reduce to counting how many spaces you
have? You can do this by using the translate() function to delete
spaces. Putting the two together, you have:
<xsl:variable name="norm" select="normalize-space(.)"/>
<xsl:variable name="spaces" select="
string-length(translate($norm, ' ', ''))"
<xsl:if test="$spaces > 1"> ...
This will pick out "D. J. Smith" and "D J Smith" but not "D.J. Smith"
or "D. Smith" or "DJ Smith". It will also choose "Dr. J. Smith" and
Mr. Smith, Bsc." which you might not want.
And don't forget the comment explaining what it is you are doing...
Traditional training & distance learning,
Consultancy by email
Melvaig Software Engineering Limited
voice: +44 (0) 1445 771 271
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list