This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

< problem

 
Nils Persson
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • 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
 
Holger Prause
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • 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.
 
Trina Thach
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I used the disable-output-escaping="yes" and it works fine.
Thanks to all.
Nils
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic