Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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.

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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....

  • #3
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Ok, mesa moron spreading misinformation:

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

    Read that for the pseudo-attributes...

  • #5
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •