Connecting Tech Pros Worldwide Forums | Help | Site Map

Script to get XSLT-transformed XML data into JS object

Curious
Guest
 
Posts: n/a
#1: Jul 20 '05
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?

Martin Honnen
Guest
 
Posts: n/a
#2: Jul 20 '05

re: Script to get XSLT-transformed XML data into JS object




Curious wrote:

[color=blue]
> 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?[/color]

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/

Steve van Dongen
Guest
 
Posts: n/a
#3: Jul 20 '05

re: Script to get XSLT-transformed XML data into JS object


Martin Honnen <mahotrash@yahoo.de> wrote:
[color=blue]
>
>
>Curious wrote:
>
>[color=green]
>> 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?[/color]
>
>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[/color]

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
Curious
Guest
 
Posts: n/a
#4: Jul 20 '05

re: Script to get XSLT-transformed XML data into JS object


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.
Curious
Guest
 
Posts: n/a
#5: Jul 20 '05

re: Script to get XSLT-transformed XML data into JS object


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

Cheers.
Closed Thread