Script to get XSLT-transformed XML data into JS object

C

Curious

Sorry for the ugly subject!

I have an XML file which I'm rendering using XSLT in IE6. I want to
transform the original XML into a Javascript object.

Example:

foo.xml has

<?xml-stylesheet type="text/xsl" href="bar.xslt" ?>
<somedata>
<firstobject>further nested stuff
</firstobject>
</somedata>

Bar.xslt encodes
....
<script language="JavaScript" type="text/javascript">

var mystuff = <some function that allows the following>
mystuff.firstobject....

</script>

Anyone have such a function?
 
M

Martin Honnen

Curious wrote:

I have an XML file which I'm rendering using XSLT in IE6. I want to
transform the original XML into a Javascript object.

Example:

foo.xml has

<?xml-stylesheet type="text/xsl" href="bar.xslt" ?>
<somedata>
<firstobject>further nested stuff
</firstobject>
</somedata>

Bar.xslt encodes
...
<script language="JavaScript" type="text/javascript">

var mystuff = <some function that allows the following>
mystuff.firstobject....

</script>

Anyone have such a function?

Maybe
document.XMLDocument
is what you are looking for, it is a property of the document object
which points to original XML as a DOM document object
 
S

Steve van Dongen

Martin Honnen said:
Curious wrote:



Maybe
document.XMLDocument
is what you are looking for, it is a property of the document object
which points to original XML as a DOM document object

I believe what he's looking for is a XSLT that would generate (for the
XML above) this:
var mystuff = {
firstobject: "further nested stuff"
}

Or if the XML was, for example
<somedata>
<a>
<b c="1">
<d />
</b>
<b />
<e>text</e>
</a>
</somedata>
then
var mystuff = {
a: {
b: [
{ c: 1, d: null },
null
],
e: "text"
}
}

Does that sum up your question?

I have a function that takes a XML DOM node and generates a JScript
object as I described above by walking the DOM, not by applying XSLT.
I'm virtually certain I can't just release it to the public domain...

Regards,
Steve
 
C

Curious

Is there a place to get info on XMLDocument's properties? My usual
suspects are silent. I found XmlDocument at MSFT, but that doesn't
seem to be the same. I have tried things like
document.XMLDocument.outerXML, document.XMLDocument.location, and
variations, but it all returns undefined.

Steve's function seems like the ticket here. If I could generate that
function with XSLT, that would work, too, I think.

Thanks.
 
C

Curious

Steve, your function sounds like what I'm after, or as you suggest, an
XSLT that puts everything together.

Cheers.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top