Viewing one XML using multiple XSL files

Discussion in 'XML' started by Toby Newman, Jan 25, 2007.

  1. Toby Newman

    Toby Newman Guest

    I started learning XML on Monday.

    I have an XML file and have written an XSL file to render it to HTML for
    formatted viewing in a browser. I'd like to create a second alternative
    view of the same data. I am confused how:

    If the following line, which dictates which XSL file should be
    used to transform my XML document for me, is found *in the XML file
    itself* then how can you use more than one XSL to present multiple views
    of the same XML document?

    <?xml-stylesheet type="text/xsl" href="myXSL.xsl"?>

    Am I approaching this the wrong way?

    --
    -Toby
    Add the word afiduluminag to the subject to circumvent my email filters.
     
    Toby Newman, Jan 25, 2007
    #1
    1. Advertising

  2. Toby Newman wrote:

    > If the following line, which dictates which XSL file should be
    > used to transform my XML document for me, is found *in the XML file
    > itself* then how can you use more than one XSL to present multiple views
    > of the same XML document?
    >
    > <?xml-stylesheet type="text/xsl" href="myXSL.xsl"?>


    The xml-stylesheet processing instruction is modelled after the HTML
    link element so it should allow you (in theory) to have several such
    processing instructions to suggest alternative stylesheets.
    However in reality for XSLT stylesheet I don't think any of the major
    desktop browsers like IE 6 and later, Mozilla/Firefox or Opera support that.
    On the other hand such a processing instruction does not prevent you to
    use script and an XSLT processor API on the server to apply different
    stylesheet as you like or want.




    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 25, 2007
    #2
    1. Advertising

  3. Toby Newman

    Toby Newman Guest

    On 2007-01-25, Martin Honnen <> wrote:
    > Toby Newman wrote:
    >
    >> If the following line, which dictates which XSL file should be
    >> used to transform my XML document for me, is found *in the XML file
    >> itself* then how can you use more than one XSL to present multiple views
    >> of the same XML document?
    >>
    >> <?xml-stylesheet type="text/xsl" href="myXSL.xsl"?>

    >
    > The xml-stylesheet processing instruction is modelled after the HTML
    > link element so it should allow you (in theory) to have several such
    > processing instructions to suggest alternative stylesheets.
    > However in reality for XSLT stylesheet I don't think any of the major
    > desktop browsers like IE 6 and later, Mozilla/Firefox or Opera support that.
    > On the other hand such a processing instruction does not prevent you to
    > use script and an XSLT processor API on the server to apply different
    > stylesheet as you like or want.


    Would it be possible to encode the filename of the XSL that I want to
    use in the URL?
    Like this:

    http://www.domain.com/myxml.xml?XSLT=viewOne.xsl
    http://www.domain.com/myxml.xml?XSLT=viewTwo.xsl

    I've done this before in PHP and know how to get the variables from the
    URL using PHP. I'm not using PHP files now, though, I'm using XML files.
    XML files aren't server-side scripted, though, so can I fetch the
    variable somehow in from the URL within XML?

    --
    -Toby
    500 Nintendo Stars for trade: 2xWii Play
    * * * * * * * * * * * * * * * * * * * * * * *
    Add the word afiduluminag to the subject to circumvent my email filters.
     
    Toby Newman, Jan 25, 2007
    #3
  4. Toby Newman wrote:

    > Would it be possible to encode the filename of the XSL that I want to
    > use in the URL?
    > Like this:
    >
    > http://www.domain.com/myxml.xml?XSLT=viewOne.xsl
    > http://www.domain.com/myxml.xml?XSLT=viewTwo.xsl
    >
    > I've done this before in PHP and know how to get the variables from the
    > URL using PHP. I'm not using PHP files now, though, I'm using XML files.
    > XML files aren't server-side scripted, though, so can I fetch the
    > variable somehow in from the URL within XML?


    You need server-side scripting reading out the query string and running
    the transformation e.g.
    http://example.com/transform.php?xml=myxml.xml&xslt=viewOne.xsl
    then transform.php reads out the file names, runs the transformation and
    sends the transformation result to the client.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 25, 2007
    #4
  5. Toby Newman

    Toby Newman Guest

    On 2007-01-25, Martin Honnen <> wrote:
    > Toby Newman wrote:
    >
    >> Would it be possible to encode the filename of the XSL that I want to
    >> use in the URL?
    >> Like this:
    >>
    >> http://www.domain.com/myxml.xml?XSLT=viewOne.xsl
    >> http://www.domain.com/myxml.xml?XSLT=viewTwo.xsl
    >>
    >> I've done this before in PHP and know how to get the variables from the
    >> URL using PHP. I'm not using PHP files now, though, I'm using XML files.
    >> XML files aren't server-side scripted, though, so can I fetch the
    >> variable somehow in from the URL within XML?

    >
    > You need server-side scripting reading out the query string and running
    > the transformation e.g.
    > http://example.com/transform.php?xml=myxml.xml&xslt=viewOne.xsl
    > then transform.php reads out the file names, runs the transformation and
    > sends the transformation result to the client.


    Ack - that's a shame. I don't have PHP or ASP on the server I'm using -
    it's a Sharepoint server and ASP is blocked. Is there any other way?

    --
    -Toby
    500 Nintendo Stars for trade: 2xWii Play
    * * * * * * * * * * * * * * * * * * * * * * *
    Add the word afiduluminag to the subject to circumvent my email filters.
     
    Toby Newman, Jan 25, 2007
    #5
  6. In article <45b8b5fd$0$27620$-online.net>,
    says...
    > You need server-side scripting reading out the query string and running
    > the transformation e.g.
    > http://example.com/transform.php?xml=myxml.xml&xslt=viewOne.xsl
    > then transform.php reads out the file names, runs the transformation and
    > sends the transformation result to the client.


    Curiosity Question:
    So, does this mean that the script needs to read the XML file and make
    changes to it before sending it to the browser? Is this what is commonly
    meant when you say "transform"?

    If that is so, then couldn't one write javascript code that reads the XML
    file from wherever it is on the internet and converts (transforms) that
    one line to whatever is needed then sends the rest on to the browser? I
    know diddly about javascript, but from what I have gathered it can read
    files from the internet and it can send HTML to the browser so that the
    browser acts as if it just read it directly off of the web site. So, if
    the javascript fed the browser an XML file with that one line modified
    would the browser then act as if it just read that XML file directly off
    of a web site and then do the XSL transformation itself?

    Naturally, that would slow down the display because the XML file was
    being processed twice but it might work.

    Perhaps one could even embed the XML file permanently into the javascript
    code. Then the XML would be transmitted at the same time as the
    javascript code and would already be on the client's computer. This would
    be like writing a program to display a page of text by simply writing a
    bunch of cout statements (C++) rather than simply saving and opening the
    text file. Naturally, the down side to this is that you no longer have a
    true XML file that can be parsed. Maybe you could also write a little
    utility that would automatically embed any XML file you wanted into a
    similar javascript program to make it easy to generate these javascript
    programs. But now I am making it way too complicated.
     
    Grant Robertson, Jan 26, 2007
    #6
  7. Grant Robertson wrote:
    > In article <45b8b5fd$0$27620$-online.net>,
    > says...
    >> You need server-side scripting reading out the query string and running
    >> the transformation e.g.
    >> http://example.com/transform.php?xml=myxml.xml&xslt=viewOne.xsl
    >> then transform.php reads out the file names, runs the transformation and
    >> sends the transformation result to the client.

    >
    > Curiosity Question:
    > So, does this mean that the script needs to read the XML file and make
    > changes to it before sending it to the browser? Is this what is commonly
    > meant when you say "transform"?


    With transform I am talking about XSLT transformations, usually in the
    context of the web XML is being transformed with an XSLT stylesheet to
    HTML as that is what browsers can render.

    > If that is so, then couldn't one write javascript code that reads the XML
    > file from wherever it is on the internet and converts (transforms) that
    > one line to whatever is needed then sends the rest on to the browser? I
    > know diddly about javascript, but from what I have gathered it can read
    > files from the internet and it can send HTML to the browser so that the
    > browser acts as if it just read it directly off of the web site. So, if
    > the javascript fed the browser an XML file with that one line modified
    > would the browser then act as if it just read that XML file directly off
    > of a web site and then do the XSL transformation itself?


    If you have ASP/J(ava)Script on the server then you can run the XSLT
    transformation on the server (PHP was only mentioned as an example). It
    would also be possible to simply change the xml-stylesheet processing
    instruction and send the XML to the client but relying on client-side
    XSLT support if the transformation can be done on the server does not
    necessarily sound like a good idea.
    However the original already pointed out that he does not have ASP on
    his server.





    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 26, 2007
    #7
  8. In article <45ba1560$0$5710$-online.net>,
    says...
    > With transform I am talking about XSLT transformations, usually in the
    > context of the web XML is being transformed with an XSLT stylesheet to
    > HTML as that is what browsers can render.


    Can't a browser open a raw XML file and apply the XSL itself? Or is XSL
    different enough from XSLT that I am totally off base? When I open some
    XML files with my browser I get a little bit of formatting over and above
    just what a text file gets. But when I open some XML files I get a
    message that says that there was no XSL file specified so the browser
    just applied a default style.

    Does XSLT perform transformations that can only be done on a server and
    then send out the HTML to the browser or is it possible for a browser to
    perform the transformations itself? I'm guessing older browsers couldn't
    do it but could newer ones?
     
    Grant Robertson, Jan 26, 2007
    #8
  9. Grant Robertson wrote:
    > Can't a browser open a raw XML file and apply the XSL itself?


    Yes, a good browser really should be able to do so; that was sorta the
    original design point for stylesheets generally. I'm not sure which
    browsers can do it these days; I've mostly been running stand-alone XSLT
    engines.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Jan 26, 2007
    #9
  10. Martin Honnen <> writes:

    > Toby Newman wrote:
    >
    >> If the following line, which dictates which XSL file should be
    >> used to transform my XML document for me, is found *in the XML file
    >> itself* then how can you use more than one XSL to present multiple views
    >> of the same XML document?
    >>
    >> <?xml-stylesheet type="text/xsl" href="myXSL.xsl"?>

    >
    > The xml-stylesheet processing instruction is modelled after the HTML
    > link element so it should allow you (in theory) to have several such
    > processing instructions to suggest alternative stylesheets.
    > However in reality for XSLT stylesheet I don't think any of the major
    > desktop browsers like IE 6 and later, Mozilla/Firefox or Opera support
    > that.
    > On the other hand such a processing instruction does not prevent you
    > to use script and an XSLT processor API on the server to apply
    > different stylesheet as you like or want.


    In some cases using trivial xml file for tying xsl and xml may help.

    <?xml-stylesheet type="text/xsl" href="myXSL.xsl"?>
    <xml-file href="myXML.xml" />

    It will require your myXSL.xsl style-sheet to process myXML.xml file when
    processing xml-file.


    --
    [pl>en: Andrew] Andrzej Adam Filip : :
    Home site: http://anfi.homeunix.net/
     
    Andrzej Adam Filip, Jan 27, 2007
    #10
  11. Grant Robertson wrote:

    > Can't a browser open a raw XML file and apply the XSL itself?


    Yes, but the original question is that someone wants to offer several
    different stylesheet for an XML document. To that question I did reply
    that the xml-stylesheet processsing instruction in theory allows that
    but that browsers in pratice do not support that. You seem to have
    missed that original problem.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 27, 2007
    #11
  12. In article <45bb4bea$0$18842$-online.net>,
    says...
    > You seem to have
    > missed that original problem.
    >
    >

    Nah. I hyjacked the thread again. Sometimes the answers to the original
    question peaks my interest about something related. I did preface my
    question with "Curiosity Question:". I guess I should have changed the
    subject line as well. Would people here prefer that I start an entirely
    new thread also? In most of usenet people have gotten so lax that I often
    don't go to the full effort of full netiquette any more.
     
    Grant Robertson, Jan 27, 2007
    #12
  13. Toby Newman

    Toby Newman Guest

    On 2007-01-27, Andrzej Adam Filip <> wrote:
    > Martin Honnen <> writes:
    >
    >> Toby Newman wrote:
    >>
    >>> If the following line, which dictates which XSL file should be
    >>> used to transform my XML document for me, is found *in the XML file
    >>> itself* then how can you use more than one XSL to present multiple views
    >>> of the same XML document?
    >>>
    >>> <?xml-stylesheet type="text/xsl" href="myXSL.xsl"?>

    >>
    >> The xml-stylesheet processing instruction is modelled after the HTML
    >> link element so it should allow you (in theory) to have several such
    >> processing instructions to suggest alternative stylesheets.
    >> However in reality for XSLT stylesheet I don't think any of the major
    >> desktop browsers like IE 6 and later, Mozilla/Firefox or Opera support
    >> that.
    >> On the other hand such a processing instruction does not prevent you
    >> to use script and an XSLT processor API on the server to apply
    >> different stylesheet as you like or want.

    >
    > In some cases using trivial xml file for tying xsl and xml may help.
    >
    ><?xml-stylesheet type="text/xsl" href="myXSL.xsl"?>
    ><xml-file href="myXML.xml" />
    >
    > It will require your myXSL.xsl style-sheet to process myXML.xml file when
    > processing xml-file.


    I'm a little unsure what you mean. Is this something I could do without
    server-side scripting?


    --
    -Toby
    500 Nintendo Stars for trade: 2xWii Play
    * * * * * * * * * * * * * * * * * * * * * * *
    Add the word afiduluminag to the subject to circumvent my email filters.
     
    Toby Newman, Jan 29, 2007
    #13
  14. Toby Newman <> writes:

    > On 2007-01-27, Andrzej Adam Filip <> wrote:
    >> Martin Honnen <> writes:
    >>
    >>> Toby Newman wrote:
    >>>
    >>>> If the following line, which dictates which XSL file should be
    >>>> used to transform my XML document for me, is found *in the XML file
    >>>> itself* then how can you use more than one XSL to present multiple views
    >>>> of the same XML document?
    >>>>
    >>>> <?xml-stylesheet type="text/xsl" href="myXSL.xsl"?>
    >>>
    >>> The xml-stylesheet processing instruction is modelled after the HTML
    >>> link element so it should allow you (in theory) to have several such
    >>> processing instructions to suggest alternative stylesheets.
    >>> However in reality for XSLT stylesheet I don't think any of the major
    >>> desktop browsers like IE 6 and later, Mozilla/Firefox or Opera support
    >>> that.
    >>> On the other hand such a processing instruction does not prevent you
    >>> to use script and an XSLT processor API on the server to apply
    >>> different stylesheet as you like or want.

    >>
    >> In some cases using trivial xml file for tying xsl and xml may help.
    >>
    >><?xml-stylesheet type="text/xsl" href="myXSL.xsl"?>
    >><xml-file href="myXML.xml" />
    >>
    >> It will require your myXSL.xsl style-sheet to process myXML.xml file when
    >> processing xml-file.

    >
    > I'm a little unsure what you mean. Is this something I could do without
    > server-side scripting?


    xsl script/file can "parse" additional xml files except xml file with
    xml-stylesheet so you can "reference" in your xml file additional xml
    files for processing by your xsl using document function.

    http://www.w3.org/TR/xslt#document
    <quote>
    12.1 Multiple Source Documents
    Function: node-set document(object, node-set?)
    The document function allows access to XML documents other than the
    main source document.
    </quote>

    WARNING: I have not test how it is supported by "main browsers".

    --
    [pl>en: Andrew] Andrzej Adam Filip : :
    Home site: http://anfi.homeunix.net/
     
    Andrzej Adam Filip, Jan 29, 2007
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. loveNUNO
    Replies:
    2
    Views:
    964
    loveNUNO
    Nov 20, 2003
  2. Richard R.
    Replies:
    1
    Views:
    636
    Martin Honnen
    Nov 8, 2004
  3. Replies:
    1
    Views:
    3,686
    A. Bolmarcich
    May 27, 2005
  4. Replies:
    4
    Views:
    998
    M.E.Farmer
    Feb 13, 2005
  5. Replies:
    4
    Views:
    790
    Dimitre Novatchev
    Nov 24, 2006
Loading...

Share This Page