XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old April 23rd, 2008, 10:09 AM
bodge bodge is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: UK
Posts: 207 bodge User rank is First Lieutenant (10000 - 20000 Reputation Level)bodge User rank is First Lieutenant (10000 - 20000 Reputation Level)bodge User rank is First Lieutenant (10000 - 20000 Reputation Level)bodge User rank is First Lieutenant (10000 - 20000 Reputation Level)bodge User rank is First Lieutenant (10000 - 20000 Reputation Level)bodge User rank is First Lieutenant (10000 - 20000 Reputation Level)bodge User rank is First Lieutenant (10000 - 20000 Reputation Level)bodge User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 19 h 37 m 12 sec
Reputation Power: 111
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

Reply With Quote
  #2  
Old April 23rd, 2008, 06:26 PM
atlantisstorm atlantisstorm is offline
Hang your freedom higher.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 atlantisstorm User rank is First Lieutenant (10000 - 20000 Reputation Level)atlantisstorm User rank is First Lieutenant (10000 - 20000 Reputation Level)atlantisstorm User rank is First Lieutenant (10000 - 20000 Reputation Level)atlantisstorm User rank is First Lieutenant (10000 - 20000 Reputation Level)atlantisstorm User rank is First Lieutenant (10000 - 20000 Reputation Level)atlantisstorm User rank is First Lieutenant (10000 - 20000 Reputation Level)atlantisstorm User rank is First Lieutenant (10000 - 20000 Reputation Level)atlantisstorm User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 10 h 14 m 2 sec
Reputation Power: 113
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!!"

Reply With Quote
  #3  
Old April 24th, 2008, 01:38 AM
bodge bodge is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: UK
Posts: 207 bodge User rank is First Lieutenant (10000 - 20000 Reputation Level)bodge User rank is First Lieutenant (10000 - 20000 Reputation Level)bodge User rank is First Lieutenant (10000 - 20000 Reputation Level)bodge User rank is First Lieutenant (10000 - 20000 Reputation Level)bodge User rank is First Lieutenant (10000 - 20000 Reputation Level)bodge User rank is First Lieutenant (10000 - 20000 Reputation Level)bodge User rank is First Lieutenant (10000 - 20000 Reputation Level)bodge User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 19 h 37 m 12 sec
Reputation Power: 111
Quote:
Originally Posted by atlantisstorm
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.

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?

Reply With Quote
  #4  
Old April 24th, 2008, 09:02 AM
jkmyoung jkmyoung is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 474 jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 18 m 31 sec
Reputation Power: 52
copy-of
<xsl:copy-of select="newsDescription" />

The tags are not being encoded; they were not being output at all.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Transforming XML (with HTML markup) using XSL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway