[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
> 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
|
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
|