By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,928 Members | 1,580 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,928 IT Pros & Developers. It's quick & easy.

Script to get XSLT-transformed XML data into JS object

P: n/a
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?
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a


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
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

P: n/a
Martin Honnen <ma*******@yahoo.de> wrote:


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


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
Jul 20 '05 #3

P: n/a
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.
Jul 20 '05 #4

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

Cheers.
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.