XSL on the client

M

Martin Collins

Hi,
I am trying to develop a stand alone application to run under IE6.
I have the following xml file sample.xml:
<?xml version="1.0" encoding="UTF-8"?>
<cardset>
<card>
<name>Arrest</name>
<cost>2W</cost>
</card>
</cardset>

I have the following xsl file sample.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet>
<xsl:template match="/">
<xsl:for-each select="cardset/card">
<div>
<span><xsl:value-of select="name"/></span>
<span><xsl:value-of select="cost"/></span>
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

I have the following html file sample.htm
<html>
<head>
<script type="text/javascript">
function doit() {
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("sample.xml")
// Load XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("sample.xsl")
// Transform
var e = document.getElementById("thebox")
e.innerHTML = xml.transformNode(xsl)
//alert(xml.transformNode(xsl))
}
</script>
</head>
<body>
<form><input type="button" value="Do it" onClick="doit()"></form>
<p id="thebox"></p>
</body>
</html>

What I am trying to do is open the html file click the button then have the
output of the transformed xml file sent to the innerHTML of the paragragh.

I can't seem to get it to work. Any thoughts or comments on how to get this
working would be greatly appreciated.
 
A

Andy Dingley

I can't seem to get it to work. Any thoughts or comments on how to get this
working would be greatly appreciated.

Test for error conditions, particularly after your .load() methods
Chances are that it's just failing to find one of the resources.

Also read a book on AJAX. You don't need to be _quite_ so M$oft specific
in how you do this.
 
M

Martin Collins

Test for error conditions, particularly after your .load() methods
Chances are that it's just failing to find one of the resources.

I know that the load methods work and that the files are being found. If I
uncomment the alert message at the end then I can see that the XML is being
parsed thru the XSL file. One funny thing though is that it displays UTF-16
instead of UTF-8.
 
W

wants4x

The software application is not going to be deployed in a web
environment. It runs as a stand alone application on my pc. I can
choose to use whatever webbrowser I like I suppose. I have done some
more reading and think that since I am a newbie I may have not be going
about things the right way. Here is my problem:

I have multiple XML files using the following schema:
<set>
<card>
<name>some_name</name>
<cost>some_cost</cost>
</card>
.... more card records ...
From an html page I want to be able to click a button that will cause
card records from several XML files to be rendered dynamically in the
current html page.

I figure that I need the button to call a JavaScript function. The
JavaScript function runs the following algorithim:
Load XSL file
For each XML file Do
Loads XML file
Transform the XML into html
Write html to the innerHTML of appropriate html element
End For

Is this application model feasable? Or am I such a total newbie that I
have completely missed the point of these technologies?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top