Linking XSL stylesheet to transform a XML string in aspx page

Hi,

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">
</div>


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>';
                  
           document.all.tooltip.style.visibility = "visible";
           document.all.tooltip.innerHTML = xmlstring;      
                              
}
</script>

UserInfoTransform.xslt
---------------------------
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<html>
<body>
<h2>User Info</h2>
<table border="1">
<tr>
<td>
<xsl:value-of select="UserInfo/User/FirstName" />
</td>
<td>
<xsl:value-of select="UserInfo/User/LastName" />
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


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 window.open may be blocked by popup blockers.

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

GranMod
Community Support Moderator
0
 
mshogrenCommented:
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
http://windowssdk.msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/482f8600-b2b8-45c7-87fe-de2226a62ed8.asp

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.
0
 
hi2sunilAuthor Commented:
I tried with the following code and it works fine.

Javascript function
----------------------
<xml id="xslTransform" src="UserInfoTransform.xslt">
</xml>
<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;
                 
           document.all.tooltip.style.visibility = "visible";
           document.all.tooltip.innerHTML = xmlDOM.transformNode(xslDOM);;    
                         
}
</script>

Thanks for the answer
0
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.