javascript to do an xslt transform after a browser detect

Posted on 2004-11-30
Last Modified: 2006-11-17
I have a series of XML files that follow a standard schema for filling in content on a web page.  I have an XSLT for Netscape/Mozilla, and XSLT for IE, and several other XSLT's in the works for other browsers.  I want to do a javascript that rewrites the body text of a page with the transform appropriate to the right browser, with a default to IE if the detect fails.
Question by:preserver3
    LVL 25

    Expert Comment

    if(-1 != navigator.userAgent.indexOf("MSIE"))
     // Internet Explorer
    document.write('<LINK YOUR XSLT FILE HERE">');
    else if (-1 != navigator.userAgent.indexOf("Mozilla"))
    // Netscape document.write('<LINK YOUR XSLT FILE HERE');
     // other
    } //-->
    LVL 25

    Accepted Solution

    see this example from w3schools

    <body><script type="text/javascript">// Load XML
    var xml = new ActiveXObject("Microsoft.XMLDOM")
    xml.async = false

    // Load XSL----------------------------------------------------------> here u can add different xslt's depending on the browser
    var xsl = new ActiveXObject("Microsoft.XMLDOM")
    xsl.async = false

    // Transform

    LVL 25

    Expert Comment


    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

    Join & Write a Comment

    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved." Ralph Waldo Emerson Introduction: One of the wonderful things about the web is that it makes it s…
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    733 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

    18 Experts available now in Live!

    Get 1:1 Help Now