This is a migrated thread and some comments may be shown as answers.

HTML + XSL + JavaScript Problem

1 Answer 29 Views
HTMLPlaceHolder
This is a migrated thread and some comments may be shown as answers.
Seb
Top achievements
Rank 1
Seb asked on 03 Nov 2011, 04:29 PM
Hi,

I join at the end of this thread a html code that i would like to set, as a string, in the HtmlSource property of the HTMLPlaceHolder. When I execute the HTML file with Google Chrome, no problem, it works. When I execute the HTML file with Internet Explorer 9, IE display a warning about script and active X but after I clicked "authorized" it works too. In the HTMLPlaceHolder, it'don't display anything, maybe there is a security like IE but HTMLPlaceHolder
don't display it.
Thanks to answer me

<html>


<head>


<script type='text/javascript'>


function transformxml()


{


if (document.implementation && document.implementation.createDocument)


{


// Mozilla


// XML:


var xmltxt


xmltxt=document.getElementById('xmlcode').value


if (xmltxt=='')


{


alert('The XML is empty')


return false


}


var doc=new DOMParser();


var xml=doc.parseFromString(xmltxt,'text/xml');






if (xml.documentElement.nodeName=='parsererror')


{


document.write('Error in XML<br /><br />' + xml.documentElement.childNodes[0].nodeValue);


alert('Error in XML\n\n' + xml.documentElement.childNodes[0].nodeValue);


return false;


}


// XSL:


var xsltPrs=new XSLTProcessor();


var xsltxt


xsltxt=document.getElementById('xsltcode').value


if (xsltxt=='')


{


alert('The XSLT is empty')


return false


}


xsl=doc.parseFromString(xsltxt,'text/xml');


if (xsl.documentElement.nodeName=='parsererror')


{


document.write('Error in XSLT<br /><br />' + xsl.documentElement.childNodes[0].nodeValue);


alert('Error in XSLT\n\n' + xsl.documentElement.childNodes[0].nodeValue);


return false;


}






xsltPrs.importStylesheet(xsl);





// Transform:


var result=xsltPrs.transformToFragment(xml,document);


document.getElementById('result_output').appendChild(result);


// document.replaceChild(result,window.document.childNodes[0])


}


else if (window.ActiveXObject)


{


// IE






// XML:


var xmltxt


xmltxt=document.getElementById('xmlcode').value


if (xmltxt=='')


{


alert('The XML is empty')


return false;


}


xml=new ActiveXObject('MSXML2.DOMDocument');


xml.async=false


xml.loadXML(xmltxt)


if (xml.parseError.errorCode!=0)


{


document.write('Error in XML<br /><br />Line ' + xml.parseError.line + ': ' + xml.parseError.reason);


alert('Error in XML\n\nLine ' + xml.parseError.line + ': ' + xml.parseError.reason);


return false


}


// XSL:


var xsltxt


xsltxt=document.getElementById('xsltcode').value


if (xsltxt=='')


{


alert('The XSLT is empty')


return false


}


xsl=new ActiveXObject('Microsoft.XMLDOM')


xsl.async=false


xsl.loadXML(xsltxt)


if (xsl.parseError.errorCode!=0)


{


document.write('Error in XSLT<br /><br />Line ' + xsl.parseError.line + ': ' + xsl.parseError.reason);


alert('Error in XSLT\n\nLine ' + xsl.parseError.line + ': ' + xsl.parseError.reason);


return false


}






// Transform:


document.write(xml.transformNode(xsl));


}


else


{


// No Browser support:


alert('Your browser does not support this example.');


}


}


</script>


</head>






<body onload='transformxml()'>


<div id='result_output'></div>


<textarea id='xmlcode' style='display:none'><?xml version='1.0' encoding='ISO-8859-1'?>


<!-- Edited by XMLSpy® -->


<catalog>


<cd>


<title>Empire Burlesque</title>


<artist>Bob Dylan</artist>


<country>USA</country>


<company>Columbia</company>


<price>10.90</price>


<year>1985</year>


</cd>


<cd>


<title>Hide your heart</title>


<artist>Bonnie Tyler</artist>


<country>UK</country>


<company>CBS Records</company>


<price>9.90</price>


<year>1988</year>


</cd>


<cd>


<title>Greatest Hits</title>


<artist>Dolly Parton</artist>


<country>USA</country>


<company>RCA</company>


<price>9.90</price>


<year>1982</year>


</cd>


<cd>


<title>Still got the blues</title>


<artist>Gary Moore</artist>


<country>UK</country>


<company>Virgin records</company>


<price>10.20</price>


<year>1990</year>


</cd>



</catalog>


</textarea>


<textarea id='xsltcode' style='display:none'><?xml version='1.0' encoding='ISO-8859-1'?>


<!-- Edited by XMLSpy® -->


<xsl:stylesheet version='1.0'


xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>


<xsl:template match='/'>


  <html>
 <header>
<Title>Plan de fertilisation Azoté</Title>
 </header>
  <body>

<H1 align ='center'>Plan de fertilisation Azoté</H1>
<H2 align ='center'>Campagne 2010/2011</H2>
<br/>
<table align ='center' width='90%'>
<tr>
<td>
<table>
<tr>
<td>Exploitation : </td>
<td>EARL du LAI</td>
</tr>
<tr>
<td>Parcelle : </td>
<td><b>Pylones 5</b></td>
</tr>
<tr>
<td>Ilot : </td>
<td>n°3</td>
</tr>
<tr>
<td>Surface : </td>
<td>9,83 ha</td>
<td>Epandable : </td>
<td>9,83 ha</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>Date du conseil : </td>
<td>15/10/2011</td>
</tr>
<tr>
<td>Localisation : </td>
<td>LIEUVIN</td>
</tr>
<tr>
<td>Type de sol : </td>
<td>LIMON ARGILEUX</td>
</tr>
</table>
</td>
</tr>
</table>
<br/>
<table align ='center' width='90%'>
<tr>
<td>
<table>
<tr>
<td>Culture : </td>
<td>BLE TENDRE HIVER</td>
</tr>
<tr>
<td>Variété : </td>
<td>Altigo</td>
</tr>
<tr>
<td>Objectif rdt : </td>
<td>90 q/ha</td>
</tr>
<tr>
<td>Semis : </td>
<td>16/10/2010</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>CIPAN : </td>
<td>Aucune</td>
</tr>
<tr>
<td>Développement : </td>
<td>-</td>
</tr>
<tr>
<td>Implantation : </td>
<td>-</td>
</tr>
<tr>
<td>Destruction : </td>
<td>-</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>Précédent : </td>
<td>BETTERAVE SUCRIERE</td>
</tr>
<tr>
<td>Résidus : </td>
<td>Enfouis non broyés</td>
</tr>
<tr>
<td>Implantation : </td>
<td>15/03/2010</td>
</tr>
<tr>
<td>Récolte : </td>
<td>02/10/2010</td>
</tr>
</table>
</td>
</tr>
</table>
<br />
<br />
<br />
<br />
<h2 align ='center'>My CD Collection</h2>
<table align ='center' border='1'>
 <tr bgcolor='#9acd32'>
 <th>Title</th>
 <th>Artist</th>
</tr>
<xsl:for-each select='catalog/cd'>
 <tr>
<td><xsl:value-of select='title'/></td>
<td><xsl:value-of select='artist'/></td>
</tr>
</xsl:for-each>
</table>
<br />
<br />
<br />
<br />
<H6 align='left'>MODALITES DE GESTION DE L'INTERCULTUREPREVUE</H6>
<table align='left'>
<tr>
<td>Devenir des residus de récolte : </td>
<td>exportés</td>
</tr>
<tr>
<td>Devenir des repousses de culture en place : </td>
<td>détruites</td>
</tr>
<tr>
<td>Implantation de CIPAN après la culture : </td>
<td>Moutarde Blanche</td>
</tr>
<tr>
<td>Implantation  : </td>
<td>25/08/2012</td>
<td>Destruction : </td>
<td>01/12/2012</td>
</tr>
</table>
  </body>


  </html>


</xsl:template>


</xsl:stylesheet>


</textarea>


</body>


</html>

1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 08 Nov 2011, 12:23 PM
Hi Seb,

When you set the RadHtmlPlaceholder.HtmlSource property the control creates a div element and adds it in the web page which is hosting the Silverlight plug-in. Then the value of the HtmlSource property is set as the div's innerHtml through a JavaScript method. This means that in your case the HtmlPlaceHolder log will try to create a div element and set its content to an html page. However, this isn't a valid scenario and as you noted it cannot be properly rendered in all browsers.

This is why in your case it is better to use the UrlSource property of the RadHtmlPlaceholder. Basically the RadHtmlPlaceholder allows you to display external pages by using an IFrame object to display the SourceUrl. But you should keep in mind that the IFrame obect is placed on top of the Silverlight plug-in in the page hosting the SL application and this is why the control's content is positioned over the whole Silverlight application.

In your scenario you can create an html page displaying the xml content and then set its URL as the UrlSource property of the RadHtmlPlaceholder. Please give this approach a try and let us know if it works for you.

If it doesn't can you please send us a sample project where we can test your scenario. That would be greatly appreciated.

Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
HTMLPlaceHolder
Asked by
Seb
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or