[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Converting embedded URLs int hot links via XSL

Subject: RE: Converting embedded URLs int hot links via XSL
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Fri, 16 Apr 2004 17:23:40 -0400
embedded urls
> From: Ghulam Abbas [mailto:abbasg_99@xxxxxxxxx] 
> Here is the sample xml
> 
> <strings>
> <str>Test url string: 'http://www.yahoo.com' and one
> more url "https://www.yahoo.com"</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="http://www.yahoo.com" 
> target="_blank">'http://www.yahoo.com'</a> and one more url 
> <a href="https://www.yahoo.com" 
> target="_blank">"https://www.yahoo.com"</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
xsl:when.  

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 -

http://fxsl.sourceforge.net

Cheers,

Tom P

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.