• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

< problem

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to write an HTML link in my .xml file. I have tried with <![CDATA[<a href=...>LINK</a>]]> but I keep getting & (amp)lt; so it just write the whole link including the <> to the screen. I want it to be a link - how do I do that?
Nils
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simply put
<a href=...>LINK</a>
in your XML (make sure it is a valid XML: all attribute values are enclosed in quotes and so on...) Then in your XSL stylesheet you can write something like
<xsl:template match="a">
<xsl:copy-of select="."/>
</xsl:template>

and you should have a perfect HTML link
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

i had the same problem a time ago because i save unser input from a htlm Form into an xml File.I display this text lateron with xslt and cocoon.

Saving the links explicitly as CDATA is the right way.
the just get the value with xslt
<xsl:value-of select="//NewsText" disable-output-escaping="yes"/>
the attribute
disable-output-escaping="yes" is very important because i tells the xslt Processor
not to convert <> into &lt&gt
Bye,
Holger

 
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both variants will work.
CDATA looks not quite elegant for me, since its content implies something that is not XML, but this solution has its advantages. CDATA section will not be parsed = less overhead during transformation. On the other hand, if you include �pure HTML� in your XML document, its well-formedness will be nicely checked for you.
But for most practical applications, there is no huge difference, really.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Say in .xml you have:
<profile>
<fname>My name</fname>
<homepage>www.somewebsite.com.au</homepage>
</profile>
In .xsl, simply put:
<xsl:for-each select="profile">
<a>
<xsl:attribute name="href">
<xsl:value-of select="homepage" />
</xsl:attribute>
<xsl:value-of select="homepage" />
</a>
</xsl:for-each>
It's a bit long but it works and easy to understand.

------------------
T.T
 
Nils Persson
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used the disable-output-escaping="yes" and it works fine.
Thanks to all.
Nils
 
Lookout! Runaway whale! Hide behind this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic