XML & xHTML

Aoami

I am a FH squatter
Joined
Dec 22, 2003
Messages
11,223
I have a table in an XML file, styled with an xslt file. Basically, I want to display this table inside a <div> in an xhtml page. I have tried the example on w3schools which displays the table but ignores any styling in the xslt file, so doesn't have table headers or anything. One way around this is to add an extra row to the xml file containing the headers, but i'm still finding it impossible to style.

Is it possible to do what I want using a http request or something like that? Been looking online for ages but can't find exactly what I need.

CHeers
 

Aoami

I am a FH squatter
Joined
Dec 22, 2003
Messages
11,223
Ok, so i've done it, using this tutorial XSLT on the Client. However, here is how my code looks:-

Code:
<div id="falctable" > <!--falcons conference table space div-->

<html>
<head>
<script type="text/javascript">
    function loadXMLDoc(dname) {
        if (window.XMLHttpRequest) {
            xhttp = new XMLHttpRequest();
        }
        else {
            xhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xhttp.open("GET", dname, false);
        xhttp.send("");
        return xhttp.responseXML;
    }

    function displayResult() {
        xml = loadXMLDoc("conference.xml");
        xsl = loadXMLDoc("conference.xslt");
        // code for IE
        if (window.ActiveXObject) {
            ex = xml.transformNode(xsl);
            document.getElementById("falctable").innerHTML = ex;
        }
        // code for Mozilla, Firefox, Opera, etc.
        else if (document.implementation && document.implementation.createDocument) {
            xsltProcessor = new XSLTProcessor();
            xsltProcessor.importStylesheet(xsl);
            resultDocument = xsltProcessor.transformToFragment(xml, document);
            document.getElementById("falctable").appendChild(resultDocument);
        }
    }
</script>
</head>
<body onload="displayResult()">
</body>
</html>

</div> <!--end falcons table space div-->

Obviously, having an html tag inside a div will not validate, and I can't think of a way around it. Any help?
 

Aoami

I am a FH squatter
Joined
Dec 22, 2003
Messages
11,223
So just moved the javascript inside my <head> in the xhtml, but can only get the table to load inside the <div> using <body onload="displayResult()" /> inside the <div> tags, which still doesn't validate.

Code:
<head>

<meta http-equiv="content-type" 
		content="text/html;charset=utf-8" />

<link rel="stylesheet" href="fixturescss.css" type="text/css" media="screen" />

<title>Fixtures and Results</title>

<link rel="shortcut icon" href="Images/favicon.ico" />

<script type="text/javascript">
    function loadXMLDoc(dname) {
        if (window.XMLHttpRequest) {
            xhttp = new XMLHttpRequest();
        }
        else {
            xhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xhttp.open("GET", dname, false);
        xhttp.send("");
        return xhttp.responseXML;
    }

    function displayResult() {
        xml = loadXMLDoc("conference.xml");
        xsl = loadXMLDoc("conference.xslt");
        // code for IE
        if (window.ActiveXObject) {
            ex = xml.transformNode(xsl);
            document.getElementById("falctable").innerHTML = ex;
        }
        // code for Mozilla, Firefox, Opera, etc.
        else if (document.implementation && document.implementation.createDocument) {
            xsltProcessor = new XSLTProcessor();
            xsltProcessor.importStylesheet(xsl);
            resultDocument = xsltProcessor.transformToFragment(xml, document);
            document.getElementById("falctable").appendChild(resultDocument);
        }
    }
</script>

</head>

<body>

<div id="falctable"  > <!--falcons conference table space div-->

<body onload="displayResult()" />

</div> <!--end falcons table space div-->

</body>
 

ST^

Can't get enough of FH
Joined
Dec 22, 2003
Messages
2,351
I'd imagine this is the kinda thing you should do on the server side, if you can.
 

Aoami

I am a FH squatter
Joined
Dec 22, 2003
Messages
11,223
Yeah i think you're right but I can't really do that atm. Just been given the login details to the webhost, and have been confronted with this CPanelX bullcrap that I can't use at all, and need to get this done first before I can start learning that.
 

Aoami

I am a FH squatter
Joined
Dec 22, 2003
Messages
11,223
nm, fixed it. was being a simpleton as per.

but it doesnt load in IE. obviously :(
 

Aoami

I am a FH squatter
Joined
Dec 22, 2003
Messages
11,223
Got my head around this cpx thing, the xml doesnt display in the live version at all, in any browser but still displays locally in everything except IE. Interesting.
 

Users who are viewing this thread

Top Bottom