473,382 Members | 1,442 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,382 software developers and data experts.

Accessing XML through the XSLT layer...

Hi all,
Ive been struggling with a problem for a little, and I can't seem to find any info on it.

I am loading an XML file into the browser and that file references an XSLT file as it's default view to be used (e.g. casting the XML data into pretty, formatted XHTML)

Is there any way for the resulting document to access the XML that is it's source? (i.e. can I read the XMLs DOM through javascript?)

For example if I have an XML-encoded list of places, and I display it on screen along with an add-new-place form, is there any way I can have that form write back directly into the xml then refresh the display so I see it added into the page without modifying the value on the server?

For reference, the thing I'm trying to do is much more complex than this, but this is the essence of the problem. To write an XSLT that allows editing of the XML.

Oh, and there are good reasons for not doing this via the server. It needs to happen locally.

Hopeful regards,
Keith Ealanta
Aug 23 '07 #1
4 1879
Dököll
2,364 Expert 2GB
Hey Keith!

Please try this site: http://www.w3schools.com/xsl/xsl_transformation.asp

Write if added info needed, good luck!

Dököll
Aug 24 '07 #2
jkmyoung
2,057 Expert 2GB
So do you mean: You have a form, such that when you click the button, it triggers a onclick() event.
This onclick() function uses javascript to add nodes back to the current document.

You also need another button to save the result document into the original source file.

If that's what you're asking it should be possible:

1. Setup of your form: Tag each of your input boxes with a unique 'id' attribute. This way, you can use the getElementById function to more quickly get the input values.

2. Changing your document on the onclick function:
Using methods like document.createTextNode or document.createElement, create the appropriate new xml nodes to be added to your document. Append them to each other and the document through methods like node.appendChild.

3. Saving your document back to your source file.
Note, that doing this may cause users to be unable to run the javascript due to security settings, as any sort of writing to file (especially an existing file) through javascript is more virus like. You could try using a FileSystemObject: eg
fso = new ActiveXObject('Scripting.FileSystemObject');
Aug 24 '07 #3
Thanks for the reply.
Essentially that was what I was wanting, but I'm trying to avoid the need to save back (at least normally - I want save back but that's a separate part)

In essence what I want is...

User loads xml file with associated xslt, seeing as a result an xhtml or svg file displaying the xml as translated by the xslt.
Within the output result is javascript for editing the underlying xml (linked to onClicks or similar)
Ideally this would directly edit the local xml and the xslt could then be triggered to reparse it - all in the users browser. i.e. not saving back at all.
The result would then be that the user could make a number of changes to the document, and only save when ready. Also the user could save the xml locally and still see the correct results when they reopened it.

The problem is I can see no way to access the xml from within the post-xslt output. (even when the xslt parsing is handled client-side). I can of course pass the entire xml through the xslt as data block, but that is ugly, particularly as it's already present (for example when I view-source I see the xml, even though the output is clearly the post-xslt content.)
So that's the detail I most want (thinking, maybe egotistically, that I can handle the rest) How do I address the dom for the XML or even the raw text of the xml from within the resulting file? (oh, that, and how to trigger a reparsing by the xslt once the changes are made)

Many thanks,
Keith Ealanta

So do you mean: You have a form, such that when you click the button, it triggers a onclick() event.
This onclick() function uses javascript to add nodes back to the current document.
Almost, yes.
You also need another button to save the result document into the original source file.

If that's what you're asking it should be possible:

1. Setup of your form: Tag each of your input boxes with a unique 'id' attribute. This way, you can use the getElementById function to more quickly get the input values.

2. Changing your document on the onclick function:
Using methods like document.createTextNode or document.createElement, create the appropriate new xml nodes to be added to your document. Append them to each other and the document through methods like node.appendChild.
This is the part I can't do. The DOM shows the post-XSLT results, not the XML DOM, unless I'm missing something.

3. Saving your document back to your source file.
Note, that doing this may cause users to be unable to run the javascript due to security settings, as any sort of writing to file (especially an existing file) through javascript is more virus like. You could try using a FileSystemObject: eg
fso = new ActiveXObject('Scripting.FileSystemObject');
Sep 4 '07 #4
Hey Keith!

Please try this site: http://www.w3schools.com/xsl/xsl_transformation.asp

Write if added info needed, good luck!

Dököll
Thanks for that. As it happens that was the site I taught myself XSLT from in the first place. I can't find any answer there (though I may have missed it somehow)
As my later post suggest, the issue is kind of complex.
Firstly I should acknowledge, I am trying to push the limits alot.

My theory is that the XML and the XSLT are usually loaded into the browser then the XML is parsed to produce the displayed text.
What I want is for the displayed text to include javascript that edits the XML that was used to generate it (effectively to produce a self editing page)
All this was to happen in the browser and the file would then be sent back to the server only on the issuing of a save command.

To be clearer,
I am trying to build a map viewer/editor.

I want the user to maintain a map view that might be described as follows...

[HTML]
<map>
<image src="map/image/file.jpg" xleft="12/59/00" xright="12/59/02.5" ytop="72/23/17.0" ybottom="72/23/17.5"/>
<annotations>
<icon type="town" xloc="12/59/01.123" yloc = "72/23/17.12"/>
<icon type="town" xloc="12/59/02.001" yloc = "72/23/17.11"/>
<icon type="bridge" xloc="12/59/01.529" yloc = "72/23/17.17" rot="72.4"/>
</annotations>
</map>[/HTML]

This is parsed to an SVG file that displays the base image with the icons superimposed over it.
In addition the SVG has scripts that allow new icos to be added.
Each icon would be inserted into the annotations collection, and the XML reparsed to update the on-screen display.
Finally if save was hit, the XML would then be sent back for server-side retention if it passed all security/validity tests.
This is only one example of what I'm trying to do, but should give a clearer idea of the problems I'm facing.

In particular,
How do I edit the underlying XML in the browser?
How do I cause the browser to reparse the modified XML with the XSLT to refresh the displayed result?

Many thanks,
Keith Ealanta
Sep 4 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Rob Meade | last post by:
Hi all, I went on an XML course over a year ago and have finally got around to having a use for it, but do you think I can actually remember anything - nope!.. Ok, here's what I want to do -...
9
by: Jeff Rubard | last post by:
I am curious to know whether anyone has experience using XSLT for web XML (non-XHTML) styling, either with CSS or standalone. I myself have engaged in rather unsuccessful experiments with the...
5
by: Fred | last post by:
Not much expertise on XSLT and trying to understand it's uses when creating apps in VS.NET? If I wanted flexibility on the UI (View aspect of M.V.C.): - How does it compare with creating...
7
by: Evan Stone | last post by:
Hello All, I was just curious to see if there was some analog to XSLT in WinForms. I'd like to be able to have my data be defined in XML, then process it with some kind of style...
3
by: thomas.porschberg | last post by:
Hi, I want to read records from a database and export it in an arbitrary format. My idea was to feed a class with a String array fetched from the database and let this class fire SAX events as...
2
by: sebastian.langer | last post by:
Hi! Certainly somebody had my problem before and could give me just some hints, how to solve it: I have an xml file, which contains scientific data in a tree form. The data should be changed...
9
by: daph4ntom | last post by:
Right, I need some some views on the pros and cons of using XSLT versus ASP.NET 2.0 for the Presentation layer of an app. My company are looking at creating multiple sites and multi lingual...
0
by: krina | last post by:
I am new in this field and have just started learning XML and xslt, Now I am having a XML file.......having structure as follows..... <?xml version="1.0" encoding="UTF-8"?> <page> ...
1
by: Clark Simpson | last post by:
Hi, Apologies if this is such a simple query but if I have an ASP/.NET Application which I normally access via www.foo.com/myapp on Machine A can I access this application layer machine via a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.