Linking XSL stylesheet to transform a XML string in aspx page


I am re-posting this question, which I posted in Web development area earlier.
I have a javascript function which is called on a button click. The required functionality of this function is to transform a xml string to a html table and display inside
div tag. I have come across ways by defining Activex objects, but the requirement is just by embedding the style sheet.

DIV tag

<div id="tooltip" style="BORDER-RIGHT: #666666 1px solid; PADDING-RIGHT: 1px; BORDER-TOP: #666666 1px solid; PADDING-LEFT: 1px; Z-INDEX: 102; VISIBILITY: hidden; PADDING-BOTTOM: 1px; FONT: 10px/12px Arial,Helvetica,sans-serif; BORDER-LEFT: #666666 1px solid; COLOR: #333333; PADDING-TOP: 1px; BORDER-BOTTOM: #666666 1px solid; POSITION: absolute; BACKGROUND-COLOR: #d5d5d5; layer-background-color: #ffffcc">

Javascript function

<script language="javascript">
function Transform()
           var xmlstring = '<?xml version="1.0" encoding="ISO-8859-1" ?><?xml-stylesheet type="text/xsl"  href="UserInfoTransform.xslt" ?><UserInfo><User><FirstName>Empire Burlesque</FirstName><LastName>Bob Dylan</LastName></User></UserInfo>';
  = "visible";
           document.all.tooltip.innerHTML = xmlstring;      

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<h2>User Info</h2>
<table border="1">
<xsl:value-of select="UserInfo/User/FirstName" />
<xsl:value-of select="UserInfo/User/LastName" />

This transformation is tested with C# server side transformation. It works well, but I have to do it at the client side
If I have the div tag in another aspx second.aspx file with the
Response.Contenttype = "text/xml" and open up then it works fine. But may be blocked by popup blockers.

Please help!
Thanks in Advance
Who is Participating?
GranModConnect With a Mentor Commented:
PAQed with points refunded (250)

Community Support Moderator
There is no real way to do this without using script.  

Either you have to get the result of the transformation in second.aspx as  a server side include or by using an XMLHTTPRequest object to get the result.  Alternatively you can use a data island and the MSXML objects like in this example

The reason you can't do what you are trying to do is that the browser can't tell that there is an XML document within the HTML document that it needs to process.
hi2sunilAuthor Commented:
I tried with the following code and it works fine.

Javascript function
<xml id="xslTransform" src="UserInfoTransform.xslt">
<script language="javascript">
function Transform()
           var xmlstring = '<xml id="xmlSource"><UserInfo><User><FirstName>Empire Burlesque</FirstName><LastName>Bob Dylan</LastName></User></UserInfo></xml>';
           var xmlDOM = xmlSource.XMLDocument;
           var xslDOM = xslTransform.XMLDocument;
  = "visible";
           document.all.tooltip.innerHTML = xmlDOM.transformNode(xslDOM);;    

Thanks for the answer
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.