It's not a secret anymore!*
The moose likes XML and Related Technologies and the fly likes <  problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "&lt;  problem" Watch "&lt;  problem" New topic
Author

&lt; problem

Nils Persson
Greenhorn

Joined: May 25, 2001
Posts: 21
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
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
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

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Holger Prause
Ranch Hand

Joined: Oct 09, 2000
Posts: 47
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
Sheriff

Joined: Aug 26, 2000
Posts: 10065
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.
Trina Thach
Greenhorn

Joined: Jun 12, 2001
Posts: 18
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

Joined: May 25, 2001
Posts: 21
I used the disable-output-escaping="yes" and it works fine.
Thanks to all.
Nils
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: &lt; problem
 
Similar Threads
pop up window href
Scriptless JSP
How to pass row id of colection to next JSP page for display using Struts
Jsp with links
Capturing the element in collection that was chosen