Insert an "XML-XSLT block"  into a web page ?

Posted on 2009-04-16
Last Modified: 2013-11-18
Hi all.
I'm newbie to XML, I've just get acquainted with XML cause it gave me to a convinient way displaying data from my web to client : combination of XML & XSL.
I wonder how I can save some "xml-xsl couple of file" as a block and then embed them in my web page.  Something like :


This is all our products :

<xml src="Product_Block.xml" id="Product_Part"></xml>

Go to home page >>


Could you give me some features of XML that lead to what I'm looking for ?
Thanks for all suggestions !


This is all our products :

<xml src="Product_Block.xml" id="Product_Part"></xml>

Go to home page >>



Open in new window

Question by:gadapchetvoi
    LVL 60

    Accepted Solution

    You can embed your XML and XSLT using JavaScript.
    Here is a Internet Explorer only solution.
    If you download Sarissa library, you can make this work for all browsers

    First try this and see if it comes close to what you need

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    <html xmlns="">
    <title>Select Transform</title>
        <script language="javascript">
          function transF()
             var oXML = new ActiveXObject("Msxml2.DOMDocument");
             var oXSL = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
             var oTmpl= new ActiveXObject("Msxml2.XSLTemplate");
             var oProc ;
    	       oXML.async = false;
             oXML.resolveExternals = false;
             oXSL.async = false;
             oXSL.resolveExternals = false;
             oTmpl.stylesheet = oXSL;
             oProc = oTmpl.createProcessor();
             oProc.input = oXML;
             var resHTM = oProc.output;
             document.getElementById("prod-block").innerHTML = resHTM;
    <body onload="transF();">
    This is all our products :
    <div id="prod-block"></div>
    Go to home page >>

    Open in new window


    Author Comment


    Thanks Gertone.

    So, your solution is to use some Javascript & innerHTML attribute. Could I know why you said that it works for IE only ?  Other browser doesn't support XML-XSLT or the way you pull data from XML & apply XSLT templates works with IE only ?
    BTW, you gave me the example XSL file but the XML?
    LVL 60

    Expert Comment

    by:Geert Bormans
    - Yes, the solution is to use JavaScript to pull in the XML and XSL and execute the transform. Replace the innerhtml of the empty div with the transform result
    - This is IE only because of the way the XML and XSL objects are created. Sarissa is a JavaScript library that takes away the browser dependency. Most browsers support XSLT
    - What I gave is the html page that drives all this. You need to reference your own XML and XSLT

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
    Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

    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