Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XSLT and displaying hyperlinks in XML

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 3/8/2005 12:48:00 PM

Xero wrote:


> I know the solution to the issue I'm having is very simple but I can't
> seem to find it. I have to say I'm a total newbie when it comes to
> xml/xslt. Here are my xml and xslt files:
> 

>         <Body>Some text some text some text some text some text some
> http://www.msn.com text</Body>


>       <xsl:value-of select="Body"/>

> Question: How do I make those hyperlinks in the Body show as actual
> hyperlinks? If I simply turn it into
> 
> <Body>Some text some text some text <a
> href="http://www.google.com">http://www.google.com</a> text some text
> some text some text</Body>
> 
> it won't work. it still shows as text. How do I do this?

If you are able to change the input XML before you apply the XSLT e.g. 
you have
   <Body>
     Some text some text some text
     <a
href="http://www.google.com">http://www.google.com</a>
       text some text
some text some text</Body>
in the input XML then it is rather easy, simply do
   <xsl:template match="Body">
     <p>
       <xsl:apply-templates />
     </p>
   </xsl:template>

   <xsl:template match="a">
     <xsl:copy>
       <xsl:apply-templates select="@* | node()" />
     <xsl:copy>
   </xsl:template>

   <xsl:template match="@*">
     <xsl:copy />
   </xsl:template>

and then where you have
   <xsl:value-of select="Body"/>
use
   <xsl:apply-templates select="Body" />
instead, that way the content of <Body> is recursively processed, text 
nodes are copied and elements like <a> are copied too.

If you are not able to change the input XML then it is difficult with 
XSLT 1.0 as then you have to write a recursive template processing the 
text content of <Body> and finding the URL to transform it into a HTML link.

-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/


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