|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
|
|
#1
|
|||
|
|||
|
Transforming XML (with HTML markup) using XSL
Hi all,
I am currently working on a project where I need to transform an XML document (tha contains HTML markup) to HTML using XSL. For example: Code:
<school>
<schoolName>MySchool</schoolName>
<schoolUrl>http://www.google.com/</schoolUrl>
<newsItem>
<newsUrl>http://www.apple.com/uk</newsUrl>
<newsTitle>New Test Item</newsTitle>
<newsDescription><P>This is where the news description would go</P></newsDescription>
</newsItem>
</school>
then an XSL of: Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="school">
<h3>
<xsl:value-of select="schoolName" />
</h3>
<xsl:apply-templates select="newsItem" />
</xsl:template>
<xsl:template match="newsItem">
<xsl:variable name="newsUrl">
<xsl:value-of select="newsUrl" />
</xsl:variable>
<li>
<h3>
<xsl:value-of select="newsTitle" />
</h3>
<div class="description">
<xsl:value-of select="newsDescription" />
(<a href="{$newsUrl}"><xsl:value-of select="newsUrl"/></a>)
</div>
</li>
</xsl:template>
</xsl:stylesheet>
The trouble being that the tags such as <P> are being encoded and output as strings rather than interpreted as HTML markup. (a better explanation can be found on this thread but the solution doesn't seem to work for me!) I've searched the forum and google, so far I've tried wrapping the newsDescription in a CDATA tag/section: Code:
<newsDescription><![CDATA[<P>This is where the news description would go</P>]]></newsDescription> Also tried changing the namespace declarations to add xmlns:html="http://www.w3.org/1999/xhtml" to the XSL file: Code:
<xsl:stylesheet version="1.0" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> and finally tried adding the attribute 'disable-output-escaping' so the xsl statement became: Code:
<xsl:value-of select="newsDescription" disable-output-escaping="yes"/> All to no avail. Can anyone suggest a solution? thanks. P.S. Please excuse any formatting errors, I've tried to cut the problem down to the minimum required. Last edited by bodge : April 24th, 2008 at 01:36 AM. Reason: corrected stylesheet error |
|
#2
|
|||
|
|||
|
The xslt you've posted is invalid as it doesn't have a closing stylesheet reference, so I guess the problem you've described isn't directly related to the xml/xsl you've posted.
Please add... Code:
</xsl:stylesheet> ... to the end of your xsl, then let us know what problem(s) you have. ![]()
__________________
"Badges? We ain't got no badges. We don't need to badges! I don't have to show you any stinkin' badges!!" |
|
#3
|
|||
|
|||
|
Quote:
Thanks. That was just a result of me trying to simplified version of the problem. The issue is still the same. Anyone any ideas of how to resolve it? |
|
#4
|
|||
|
|||
|
copy-of
<xsl:copy-of select="newsDescription" /> The tags are not being encoded; they were not being output at all. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Transforming XML (with HTML markup) using XSL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|