Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XSLT href link

From: Joe Kesselman <keshlam-nospam@-------.--->
To: NULL
Date: 2/3/2006 9:21:00 AM
Per Johansson wrote:
> Is it possible to use XSLT to automatically create href links while it
> formats an XML document? That is, if it finds "http://me.us/" in a 
> text, it adds <a href="http://me.us/">http://me.us/</a>

Possible, yes. Easy, no.

XSLT doesn't have much in the way of built-in ability to search within 
text; it uses XPath, which mostly focuses on document structure.

But XSLT has enough capability that you can build this out of simpler 
tools. I don't have an example on hand, but take a look at some of the 
string manipulation techniques documented in the XSLT FAQ website 
(http://www.dpawson.co.uk/xsl/xslfaq.html) and they should give you some 
ideas on how to approach this. Basically, you can try to use 
substring-after() together with some logic to find the URIs, and 
recursion in place of iteration to work your way through the source text.

The other solution, if your XSLT implementation allows it, is to call 
out to an extension function written in another language. That's going 
to be less portable, but may be easier, and depending on the exact 
details of your processor and the other language may yield better 
performance.

Caveat: Not everything that looks like a URI is intended to be a URI, so 
code that tries to add the anchor elements automatically is going to 
guess wrong on occasion. As browsers have demonstrated, that usually 
isn't fatal... but it's better to have this marked up in the source 
document rather than relying on "by guess and by golly."


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent