|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Literal string question
Mike,
>I would like to select all names that have initials not seperated by
>a space. Such as:
>
>A.A. Peters
>
>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.
Example:
normalize-space() will remove leading and trailing white space, and
convert any other white space to a single space, so
" D. J. Smith "
becomes
"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($norm) -
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...
Regards,
Trevor Nash
--
Traditional training & distance learning,
Consultancy by email
Melvaig Software Engineering Limited
voice: +44 (0) 1445 771 271
email: tcn@xxxxxxxxxxxxx
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








