We help IT Professionals succeed at work.

xml and xslt proper conversion

Skwerlz
Skwerlz asked
on
I am new to xslt. I am trying to get dnn xml/xslt module to read an xml file that is used by a flash site. I have an admin center and am trying to get both to read it properly. The problem I am having is that the html tags in the cdata are displayed as plain text. I want to strip the html tags with the xslt in order to let dnn style it.

here is my xml
<news>
<n>
<head>Brand New Website!</head>
<announce>
<![CDATA[
<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="10" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0">Saeryn Studios has their own home on the web!</FONT></P></TEXTFORMAT>
]]>
</announce>
<body>
<![CDATA[
<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="10" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0">It has been a process, but it is finally here. Welcome to our new home on the web!!</FONT></P></TEXTFORMAT>
]]>
</body>
<date>11/16/2011</date>
</n>

<n>
<head>test</head>
<announce>
<![CDATA[
<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="10" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0">Saeryn Studios has their own home on the web!</FONT></P></TEXTFORMAT>
]]>
</announce>
<body>
<![CDATA[
<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="10" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0">It has been a process, but it is finally here. Welcome to our new home on the web!!</FONT></P></TEXTFORMAT>
]]>
</body>
<date>11/16/2011</date>
</n>
</news>

Open in new window


here is the xslt
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="n">
   <DIV STYLE="font-weight:bold">
      <xsl:value-of select="head" /> 
       </DIV>
   <DIV STYLE="font-weight:bold">
       <xsl:value-of select="body" />
    
</DIV> 


<div style="padding-top: 6px; padding-bottom: 6px"><hr style="width:100%; size: 2" /></div>


</xsl:template>



</xsl:stylesheet>

Open in new window

Comment
Watch Question

Information Architect
Top Expert 2006
Commented:
If you control the source XML, get rid of the CDATA section and treath the content as XML tags

If you can't get rid of the CDATA use disable-output-escaping on teh CDATA nodes

<xsl:value-of select="body" />

would be

<xsl:value-of select="body" disable-output-escaping="yes"/>

but that is not supported on all processors

Author

Commented:
That worked! Thanks for the quick help.
Unfortunately I now have super sized text on the body text. How can I control the font size and color with escaping off? I tried the following with no success.
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="n">
   <DIV STYLE="font-weight:bold">
      <xsl:value-of select="head" /> 
       </DIV>
   <DIV STYLE="font-weight:bold; font-size:12px;font-color:#999999">
       <xsl:value-of select="body" disable-output-escaping="yes"/>
    
</DIV> 


<div style="padding-top: 6px; padding-bottom: 6px"><hr style="width:100%; size: 2" /></div>


</xsl:template>



</xsl:stylesheet>

Open in new window

Gertone (Geert Bormans)Information Architect
Top Expert 2006
Commented:
well, the font size=10 will increase the base font

start of with values, 1 or 2 and see where it leads you

   <DIV STYLE="font-weight:bold; font-size:1px;font-color:#999999">
       <xsl:value-of select="body" disable-output-escaping="yes"/>
   
</DIV>

you will need to experiment a bit

Author

Commented:
It seems to be ignoring everything in the div style except font weight. Not sure what that is about. I even tried using standard html tags around the xsl value. Any ideas?
Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
Honestly?
I have no clue, maybe post a question in teh CSS TA
I have a feeling it has to do with property precedence

I would start by testing a static version of the html (the result file of the XSLT, pasted in hard coded) to see what happens

Author

Commented:
Thanks for the help.
Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
welcome,
I saw your follow up question,
good luck with that one