473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Script to get XSLT-transformed XML data into JS object

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


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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JEDI_BC | last post by:
hi, I try hardly to use javascript functions in my XSL (exslt.org) using DOM/XSL (libxslt). It works on sablotron but it is too slow and cost too much cpu. I am up to date on my software...
10
by: Fred | last post by:
Hello, After looking at various CMS tools, either server- (Drupal, Pivot, etc.) or desktop-based (CityDesk, Cute Site Builder), it occured to me that I really didn't need something that...
0
by: Phlip | last post by:
XMLians: Suppose I have an Ant script, and I want to convert it to a quicky HTML representation of itself. For esthetics, and eventually for editing and launching events, are there any XSLT...
14
by: eric.pederson | last post by:
Hi all, Finally diving into XML programmatically. Does anyone have a best practice recommendation for programmatically discovering the structure of an arbitrary XML document via Python? It...
1
by: John Moore | last post by:
I have a set of code that is called on every page load that loads an xslt file. The xslt file has an embedded <script> tag. Loading the page mutliple times causes aspnet_wp.exe to use all available...
1
by: stefano | last post by:
Hi, I have a file xml (p.xml) and I use XSLT to trasform p.xml to XHTML. this is the xml file: .... <test label="x"> <itemList> <testItem oknumber="2" > .... </testItem> </itemList>
44
by: rhythmace | last post by:
W3C HTML validator passes this: .... <script type="text/javascript" src="foo.js"> <script type="text/javascript"> ....script in here... </script> ....
8
by: toby989 | last post by:
Hi All I am completely new to this, but I was wondering if I can apply 2 xslt's subsequently to an xml, via the (client side) scripting method: http://www.w3schools.com/xsl/xsl_client.asp ...
2
by: willyWEB66 | last post by:
Hi everyone, I have this code in javascript where the XML file is loaded and displayed to an html using XSLT. It works fine in IE but not in Firefox. My problem is in the looping to the...
0
by: astroboiii | last post by:
Having a little issue with my build script. I have some EAR files that I extract WAR files from, I then extract .wsdl files from the WAR files and do some work with those wsdl files. However,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.