Linking XSL stylesheet to transform a XML string in aspx page

Posted on 2006-05-12
Last Modified: 2011-09-20

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
Question by:hi2sunil
    LVL 15

    Expert Comment

    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.
    LVL 2

    Author Comment

    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

    Accepted Solution

    PAQed with points refunded (250)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    Title # Comments Views Activity
    xsl to xslt 3 38
    Formatting an Excel formula to give correct date format 4 54
    Fetch XML Unions? 3 249
    XML error 2 36
    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now