• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 441
  • Last Modified:

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
0
hi2sunil
Asked:
hi2sunil
1 Solution
 
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
 
GranModCommented:
PAQed with points refunded (250)

GranMod
Community Support Moderator
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now