...

View Full Version : Urgent! Update and display xml output after user enters field to choose xsl format.



Thecla
08-07-2002, 04:34 AM
Ok, i'm thinking this topic requires DOM too but feels javascript is more related to the subject ?
I digress.

Anyways, i'm now scripting a program which allows a user to enter the number representing the xsl interface format via a textfield.
After that, clicking a preview button will result in a popup that will display the xml information displayed in the xsl format he has chosen earlier, assuming the xml has a predetermined xsl format initially, ie it has a predetermined format that can be changed and updated.
Assuming there are several xsl interface formats, say:
1. Horizontal interface
2. Vertical interface


Currently, i have the xml(say abc.xml) directly hardcoded to display a particular xsl.
For example, as follows:
<?xml-stylesheet type="text/xsl" href="abc.xsl"?>

And am having a popup window displaying abc.xml after the user clicks on the preview button.

Therefore all that i'm having right now is a predetermined interface format, i'm not able to update yet.

My question is, what scripting do i need in place of "abc.xsl" in
"<?xml-stylesheet type="text/xsl" href="abc.xsl"?>" so that it can actually be customisable by a click of a button after keying in the number in the field; then actually displaying the updated customised interface in the popup window.

Sorry if this is kinda long, i'm quite incoherent. :o

jkd
08-07-2002, 05:18 AM
I used PHP for a related app, just did an <?php echo $xslfile; ?> or something like inside href="" (I don't really like php, but I had Apache configured with php ready to go, and this was rather simple).

Using proprietary features of IE and Gecko, you can dynamically import XML documents and transform them according to a progmatically picked XSLT document, but I really don't like resorting to that solution.

In theory, W3C defined a "rel" pseudo-attribute to the xml-stylesheet processing instruction, in which you would go:

<?xml-stylesheet type="text/xml" href="doc1.xsl" rel="stylesheet"?>
<?xml-stylesheet type="text/xml" href="doc2.xsl" rel="alternate stylesheet"?>
<?xml-stylesheet type="text/xml" href="doc1.xsl" rel="alternate stylesheet"?>
etc

And then the browser is supposed to have a UI interface to switch between the stylesheets. Mozilla does this for CSS documents, but not for XSLT docs. No other browser even has the switch element in their UI.

What you can do though, is make use of the disabled attribute for xml-stylesheet, then use Javascript to disable all of them, then enable the one you want applied. On second thought though, I don't believe the original, untransformed XML document is exposed to browsers (at least in Mozilla), which means you couldn't disable/enable the particular xml-stylesheets...


Errr, I still think a server-side solution is the easiest/most compatible, but if you're interested, I could dig up some examples of dynamically importing XML then transforming it to XSLT and outputting it to a parent node....

Thecla
08-07-2002, 05:37 AM
Erm, one question.
<?xml-stylesheet type="text/xml" href="doc1.xsl" rel="stylesheet"?>

The above is to be coded inside the xml document right ? If so, then 'doc1.xsl' will be again hardcoded as the predetermined xsl interface for the particular xml file ? Or maybe i've misunderstood what you mean ?

Also, may i know how i can disable the attribute for the xsl-stylesheet too ?

I would think a server-side solution will be the best too but this is actually for a school project so i don't exactly have a choice. :(

jkd
08-07-2002, 06:25 AM
Ok, mesa moron spreading misinformation:

http://www.w3.org/TR/xml-stylesheet/

Read that for the pseudo-attributes...

Thecla
08-09-2002, 07:51 PM
Mm..the website didn't help much in my problem but at least i learned something from there.
Thank you so much for your help.
Anyhow, i've found the solution to the problem, ie using 'switch'.
Below is a snippet of the coding, hopefully it'll help whomever who has a similar problem too. :)

<form name="myForm1" onsubmit="return allteams()">
That's the form that'll allow the user to type in the value representing the interface format.

And below, is where all the magic lies -->

<script language="javaScript" type="text/javascript">
function xxx()
{
x=document.myForm1
txt=x.myInput1.value
if (txt>=1 && txt<=4){
switch(txt) {
case '1': txt= window.open("xxxhorizontal.htm"); break;
case '2': txt= window.open("xxxvertical.htm"); break;
case '3': txt= window.open("xxxpictures.htm"); break;
case '4': txt= window.open("xxxpara.htm"); break;
default: txt = "Not a Number";
}
return txt;
}

else
{
alert("Must be 1-4")
}
}
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum