RE: [xsl] Converting embedded URLs int hot links via XSL

Subject: RE: [xsl] Converting embedded URLs int hot links via XSL
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Fri, 16 Apr 2004 17:23:40 -0400
> From: Ghulam Abbas [mailto:abbasg_99@xxxxxxxxx] 
> Here is the sample xml
> <strings>
> <str>Test url string: '' and one
> more url "";</str>
> </strings>
> So, is there a way to extract the urls above from str
> and then convert them into hotlinks. The desired html
> is something like
> Test url string: <a href=""; 
> target="_blank">''</a> and one more url 
> <a href=""; 
> target="_blank">"";</a>
> I've tried recursion but it doesn't work. Any ideas???

Recursion *will* work, but this a really hard problem.  That is because
a general URL is hard to parse in the best of circumstances (that is,
with regular expressions or some other language that is good at that
kind of text analysis).  In addition, you can have either single or
double quotes around your url strings.

This makes for a lot of choices, and that leads to painstaking testing
of many possibilities. 

If you know that the scheme can only be http or https, that makes for
fewer choices.  If you can limit the quotes around the url string to be
just single or just double quotes, that reduces the number of choices.

Otherwise you have to work your way through the string using contains(),
substring-after(), and substring-before(), and lots of xsl:choose and

The usual way to do recursion in this kind of case is something like
this -

1) Call the template with the initial text as a parameter.
1) Split string into a "head" part and a "tail" part at some marker.
2) Process the head part (and possibly some of the "tail" part) to
produce the first part of the result.
3) Call the template again with the "rest" part as a parameter, unless
"rest" does not exist.

You might find that Dmitre Novatchev's FXSL (Functional XSL) package may
make this task easier -


Tom P

Current Thread