Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with HTML inside an XML and transform using XSL, please! 2

Status
Not open for further replies.

henryz

Programmer
Oct 3, 2001
33
0
0
AU
Hello everybody,

I use the same examples RGeo posted at 27 Aug. I encounter exactly the same problem with her. Suggestions and tips are most welcome at this stage.

This xml generated from ASP with values (in html format) from a database (SQL server) as follows:
<?xml version=&quot;1.0&quot;?>
<report>
<row>
<column><caption>ID</caption>
<value>1</value>
</column>
<column><caption>Notes</caption>
<value>Approvedby <FONT COLOR=&quot;RED&quot;><B>ABC</B></FONT></value>
</column>
</row>
</report>

One of the column elements has html embedded in it. When transformed with XSL, i need to see the HTML formatting on the page but the FONT and Bold tags appear as it is.

The xsl i use is sthg like this
<?xml version=&quot;1.0&quot;?>
<xsl:stylesheet xmlns:xsl=&quot;<xsl:template match=&quot;/&quot;>
<xsl:for-each select=&quot;report&quot;>
<table>
<xsl:for-each select=&quot;row&quot;>
<tr>
<xsl:for-each select=&quot;column&quot;>
<td><xsl:value-of select=&quot;value&quot;/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

What should i do to see effect of the HTML formatting. I tried using xsl:eek:utput and xsl:text with the disable-output-escaping option set to yes , but it did not work.

Many thanks

Henry
 
instead of <xsl:value-of select=&quot;value&quot;/>

try <xsl:copy-of select=&quot;value&quot;/>
 
I try what you suggest, it doesn't work. Thanks a lot anyway.

Henry
 
what happened? the snippet i gave was slightly incorrect. it should have printed the HTML tags but also the <value> tag as well.

i meant to say

<xsl:copy-of select=&quot;value/*&quot;/>

if this really isn't working then maybe your processor is doing something funny.
 
why don't you just add the attributes fontcolor=&quot;whatever&quot; and weight=&quot;bold&quot; to the value element in the xml...then transform it in the xsl
 
Hi Henry,
I know exactly what you mean Henry and I'm having the same problem :( I have a products XML file containing a structure representing my stock and I wanted to put HTML in the product descriptions for ease so they can be just sent out to browser. But I went through the same things you have and have had no joy. Using MSXML3.0 Parser, tried the xsl:copy suggesting with no luck and adding attributes for every possible HTML tag that might be needed isn't really viable :(
ah well, if anyone spots this thread or you get the solution Henry, please let me know!
 
if you post the code you're using i'll sort it. i dunno why what i said doesn't work for you, so maybe i'm missing something.
 
Dear MrTom,

Here is a simplified version of my products file containing 1 item. I haven't included the xsl file which was far too long but in short, any way of outputing the description contents such that browsers apply the formats would be what I'm looking for! :)
What I belive is closely related issue, I've been reading that using the CDATA in a DTD will prevent the contents from being parsed. However despite closely following the syntax of examples from and using the declaration <!ELEMENT DESCRIPTION (#CDATA)> instead of <!ELEMENT DESCRIPTION ANY>
doesn't seem to be even legal and without putting the <![CDATA[]]> around every piece of content, you cannot parse a xml file with any DTD that contains HTML.
Big puzzle for me:How does one declare CDATA in a DTD element?

<?xml version=&quot;1.0&quot;?>
<PRODUCTS>
<GAME GAMEID=&quot;MAGEKNIGHT&quot; TITLE=&quot;Mage Knight&quot;>
<DESCRIPTION>Colletable Miniature Game that looks incredible!</DESCRIPTION>
<EXPANSION TITLE=&quot;Rebellion - Series 1&quot;>
<DESCRIPTION><br/><B>Mage Knight</B></DESCRIPTION>
<ITEM STOCKID=&quot;XMLMKRebellionStarter&quot; TITLE=&quot;10 Figure Starter Set&quot;>
<DESCRIPTION>
This starter box contains: 10 figures, Eight 25mm tall figures and two 50mm tall figures, a rulebook, <b>two</b> 6-sided dice!
</DESCRIPTION>
</ITEM>
</EXPANSION>
</GAME>
</PRODUCTS>

Many Thx!
 
ok, by going through this i now see why the problem happened. putting html into xml is always a problem but i can see why you want it - if you really can, avoid doing it.
if you think in terms of me wanting to take your xml and produce a catalog of your products in a pdf document, i would get all your html in my document because the pdf doesn't know what html is.
in your xml it might be better to have the TITLE in it's own element and not as an attribute. you'll only see the benefits of this if you do a lot of xsl, but it's not greatly important.

anyway here's a stylesheet i did quickly. the important bits are the last two templates.

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<xsl:transform
version=&quot;1.0&quot;
xmlns:xsl=&quot;
<xsl:eek:utput method=&quot;xml&quot; indent=&quot;yes&quot;/>

<xsl:template match=&quot;/PRODUCTS&quot;>
<html><head><title>hello</title></head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match=&quot;GAME&quot;>
<p>Title: <b><xsl:value-of select=&quot;@TITLE&quot;/></b></p>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match=&quot;Expansion&quot;>
<p>Expansion: <xsl:value-of select=&quot;@TITLE&quot;/></p>
<xsl:apply-templates/>

<xsl:template match=&quot;ITEM&quot;>
<p>Item: <xsl:value-of select=&quot;@TITLE&quot;/></p>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match=&quot;DESCRIPTION&quot;>
<p>Description: <xsl:apply-templates mode=&quot;preserveHTML&quot;/></p>
</xsl:template>

<xsl:template match=&quot;*&quot; mode=&quot;preserveHTML&quot;>
<xsl:copy-of select=&quot;.&quot;/>
</xsl:template>
</xsl:transform>
 
Dear MrTom,

It seems it works, instead a syntax error in your xsl code, you missed a close template tag in template &quot;Expansion&quot;. But I have another question to ask, I use Microsoft.XMLDOM to generate xml files, and display over the server. The html information for the product is stored in the SQL server. While I extract the html content from the database and append to an xml node, the Microsoft.XMLDOM automatically convert the &quot;<&quot; and &quot;>&quot; tags into &quot;& lt;&quot; and &quot;& gt;&quot; ( I put a space between & and &quot;lt; gt;&quot; otherwise the browser will display &quot;<&quot; and &quot;>&quot; automatically), which make my xml file looks as this:

<?xml version=&quot;1.0&quot;?>
<?xml-stylesheet type=&quot;text/xsl&quot;?>
report>
<row>

<column><caption>ID</caption>
<value><FONT COLOR=&quot;RED&quot;& gt;& lt;B& gt;ABC& lt;/B& gt;& lt;/FONT& gt;
</value>
</column>

</row>
</report>

The xsl I use is like this:
<?xml version=&quot;1.0&quot;?>
<xsl:stylesheet
version=&quot;1.0&quot;
xmlns:xsl=&quot;
<xsl:eek:utput method=&quot;xml&quot; indent=&quot;yes&quot;/>
<xsl:template match=&quot;/&quot;>
<xsl:for-each select=&quot;report&quot;>
<table>
<xsl:for-each select=&quot;row&quot;>
<tr>
<xsl:for-each select=&quot;column&quot;>
<td><xsl:copy-of select=&quot;value&quot;/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

The output I get is not what I really want:
ID <FONT COLOR=&quot;RED&quot;><B>ABC</B></FONT>

Should any suggestions and advice will be most appreciated.

Many thanks

Henry
 
Thanks for the effort Mr Tom, I'm afraid it gives me problem Henry is decsribing, the output is coverted into codes such that the HTML is displayed in the HTML rather than being rendered as HTML.
Ah well, the search goes on!
 
Hi Clemintine,

I find a way to solve this problem. The whole idea is to create another html DOM object to store the HTML information, then append the html DOM to the original XML DOM, and use the XSL techniques we discussed in the forum, the output is exactly as I expected. I can give you more detail here if you want.

Good luck

Henry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top