I've read up on XML, but how to really use it??

Discussion in 'XML' started by Stan R., May 30, 2006.

  1. Stan R.

    Stan R. Guest

    Hi. I'm an old programmer whose been finally reading up on xml the past
    week. The concepts of xml, dtd, and xsl seem pretty straight forward to
    me. I understand that xsl (as xslt for transformations) can be used to
    transform xml data from an xml document into another document, as
    specified in the templates.

    One of the best examples I've seen by far is transforming a given xml
    doc into html.

    But where I seem to be getting stuck in the mud is how to really apply
    xml documents. I know they can be used as data holders and config files
    for regular applications. But how do you use it more directly, to, say,
    generate a webpage from an xml doc.

    Also (and this is kind of what I'm really getting at) is, is it possible
    to write web pages, so to speak, using xml and xslt. I noticed that such
    applications like Front Page 2003 (I sometimes use it as my html editor)
    let you make xml documents.

    From what I can see, I can easily make an .xml, .dtd, and .xslt files in
    a folder somewhere in the document root on my web server, but what I
    TRULY don't understand is how do I actually "call" the xslt (since it
    does the actual transformation) from the web browser? Does it need to be
    "called" from an html document, or what? This is what I'm most confused
    on, and thanks for any help clearing up the waters.

    (Also, any good real world examples for an xml+dtd+xslt would be helpful
    too.)

    --
    Stan
    Stan R., May 30, 2006
    #1
    1. Advertising

  2. Stan R.

    Guest

    Stan R. wrote:
    > Hi. I'm an old programmer whose been finally reading up on xml the past
    > week. The concepts of xml, dtd, and xsl seem pretty straight forward to
    > me. I understand that xsl (as xslt for transformations) can be used to
    > transform xml data from an xml document into another document, as
    > specified in the templates.
    >
    > One of the best examples I've seen by far is transforming a given xml
    > doc into html.


    The power of xsl lies in the fact that it can be used to transform any
    xml file into any other xml file.


    > But where I seem to be getting stuck in the mud is how to really apply
    > xml documents. I know they can be used as data holders and config files
    > for regular applications. But how do you use it more directly, to, say,
    > generate a webpage from an xml doc.
    >
    > Also (and this is kind of what I'm really getting at) is, is it possible
    > to write web pages, so to speak, using xml and xslt. I noticed that such
    > applications like Front Page 2003 (I sometimes use it as my html editor)
    > let you make xml documents.



    You cannot write to web pages(atleast without any programming support),
    but you can make the browser to create html output on the fly using
    xsl.

    > From what I can see, I can easily make an .xml, .dtd, and .xslt files in
    > a folder somewhere in the document root on my web server, but what I
    > TRULY don't understand is how do I actually "call" the xslt (since it
    > does the actual transformation) from the web browser? Does it need to be
    > "called" from an html document, or what? This is what I'm most confused
    > on, and thanks for any help clearing up the waters.


    You dont call the xsl from the browser. A simple directive in the
    beginning of the xml file will tell the browser which xsl stylesheet
    file to apply.

    For a clearer example see
    http://www.captain.at/howto-xml-xsl-example.php

    -Dhanvanth
    , May 31, 2006
    #2
    1. Advertising

  3. Stan R.

    Peter Flynn Guest

    Stan R. wrote:
    > Hi. I'm an old programmer whose been finally reading up on xml the past
    > week. The concepts of xml, dtd, and xsl seem pretty straight forward to
    > me. I understand that xsl (as xslt for transformations) can be used to
    > transform xml data from an xml document into another document, as
    > specified in the templates.
    >
    > One of the best examples I've seen by far is transforming a given xml
    > doc into html.
    >
    > But where I seem to be getting stuck in the mud is how to really apply
    > xml documents. I know they can be used as data holders and config files
    > for regular applications. But how do you use it more directly, to, say,
    > generate a webpage from an xml doc.


    You can write an XSLT transformation to do this, as you already mention
    in the previous paragraph.

    > Also (and this is kind of what I'm really getting at) is, is it possible
    > to write web pages, so to speak, using xml and xslt. I noticed that such
    > applications like Front Page 2003 (I sometimes use it as my html editor)
    > let you make xml documents.


    It's possible, but support for in-browser XML and XSLT is patchy.
    Server-side transformation is strongly recommended.

    > From what I can see, I can easily make an .xml, .dtd, and .xslt files in
    > a folder somewhere in the document root on my web server, but what I
    > TRULY don't understand is how do I actually "call" the xslt (since it
    > does the actual transformation) from the web browser?


    See the FAQ: http://xml.silmaril.ie/authors/style/

    > Does it need to be
    > "called" from an html document, or what? This is what I'm most confused
    > on, and thanks for any help clearing up the waters.


    The stylesheet has to be referenced in the XML document. The browser
    fetches it and applies it to perform the transformation.

    > (Also, any good real world examples for an xml+dtd+xslt would be helpful
    > too.)


    See the links in the FAQ (it's all done that way).
    http://xml.silmaril.ie/admin/availability/

    ///Peter

    >
    Peter Flynn, May 31, 2006
    #3
  4. Stan R.

    Stan R. Guest

    wrote:
    > Stan R. wrote:
    >> Hi. I'm an old programmer whose been finally reading up on xml the
    >> past week. The concepts of xml, dtd, and xsl seem pretty straight
    >> forward to me. I understand that xsl (as xslt for transformations)
    >> can be used to transform xml data from an xml document into another
    >> document, as specified in the templates.
    >>
    >> One of the best examples I've seen by far is transforming a given xml
    >> doc into html.

    >
    > The power of xsl lies in the fact that it can be used to transform any
    > xml file into any other xml file.
    >
    >
    >> But where I seem to be getting stuck in the mud is how to really
    >> apply xml documents. I know they can be used as data holders and
    >> config files for regular applications. But how do you use it more
    >> directly, to, say, generate a webpage from an xml doc.
    >>
    >> Also (and this is kind of what I'm really getting at) is, is it
    >> possible to write web pages, so to speak, using xml and xslt. I
    >> noticed that such applications like Front Page 2003 (I sometimes use
    >> it as my html editor) let you make xml documents.

    >
    >
    > You cannot write to web pages(atleast without any programming
    > support), but you can make the browser to create html output on the
    > fly using xsl.
    >
    >> From what I can see, I can easily make an .xml, .dtd, and .xslt
    >> files in a folder somewhere in the document root on my web server,
    >> but what I TRULY don't understand is how do I actually "call" the
    >> xslt (since it does the actual transformation) from the web browser?
    >> Does it need to be "called" from an html document, or what? This is
    >> what I'm most confused on, and thanks for any help clearing up the
    >> waters.

    >
    > You dont call the xsl from the browser. A simple directive in the
    > beginning of the xml file will tell the browser which xsl stylesheet
    > file to apply.
    >
    > For a clearer example see
    > http://www.captain.at/howto-xml-xsl-example.php


    Thank you very much.

    --
    Stan
    Stan R., May 31, 2006
    #4
  5. Stan R.

    Stan R. Guest

    Peter Flynn wrote:
    > Stan R. wrote:
    >> Hi. I'm an old programmer whose been finally reading up on xml the
    >> past week. The concepts of xml, dtd, and xsl seem pretty straight
    >> forward to me. I understand that xsl (as xslt for transformations)
    >> can be used to transform xml data from an xml document into another
    >> document, as specified in the templates.
    >>
    >> One of the best examples I've seen by far is transforming a given xml
    >> doc into html.
    >>
    >> But where I seem to be getting stuck in the mud is how to really
    >> apply xml documents. I know they can be used as data holders and
    >> config files for regular applications. But how do you use it more
    >> directly, to, say, generate a webpage from an xml doc.

    >
    > You can write an XSLT transformation to do this, as you already
    > mention in the previous paragraph.
    >
    >> Also (and this is kind of what I'm really getting at) is, is it
    >> possible to write web pages, so to speak, using xml and xslt. I
    >> noticed that such applications like Front Page 2003 (I sometimes use
    >> it as my html editor) let you make xml documents.

    >
    > It's possible, but support for in-browser XML and XSLT is patchy.
    > Server-side transformation is strongly recommended.
    >
    >> From what I can see, I can easily make an .xml, .dtd, and .xslt
    >> files in a folder somewhere in the document root on my web server,
    >> but what I TRULY don't understand is how do I actually "call" the
    >> xslt (since it does the actual transformation) from the web browser?

    >
    > See the FAQ: http://xml.silmaril.ie/authors/style/
    >
    >> Does it need to be
    >> "called" from an html document, or what? This is what I'm most
    >> confused on, and thanks for any help clearing up the waters.

    >
    > The stylesheet has to be referenced in the XML document. The browser
    > fetches it and applies it to perform the transformation.
    >
    >> (Also, any good real world examples for an xml+dtd+xslt would be
    >> helpful too.)

    >
    > See the links in the FAQ (it's all done that way).
    > http://xml.silmaril.ie/admin/availability/


    Thank you, this is more what I was after, the server side aspect (though
    the other way, referencing xml files directly, how this was done - which
    I feel really stupid for asking now given the answer was staring me
    smack in the face - was also what I was interested in.)

    Many thanks to all.

    --
    Stan
    Stan R., May 31, 2006
    #5
  6. Stan R.

    Andy Dingley Guest

    Stan R. wrote:

    > how do I actually "call" the xslt (since it
    > does the actual transformation) from the web browser?


    In general, you don't. Have the web server do it. Although you can
    attach the stylsheet to the XML document and have the web browser do
    it, that's still awfully dependent on particular browsers having XSLT
    support.

    How you do transforms on the server depends on the platform. You need
    an XSLT transform engine like MSXML or Xalan and most server-side
    languages will have a tutorial around somewhere.

    To do it on the client, then you can use this (simplest)
    http://www.w3.org/TR/xml-stylesheet/
    but it gives an "all or nothing" result, either working or not working
    and leaving a blank screen in the meantime. A few years ago M$oft were
    pushing "data islands" as an alternative, where a HTML wrapper page had
    XML and XSLT embedded within. This was quite a good technique, but too
    vendor-specific. Nowadays you should probably do some searching around
    for "AJAX" techniques (AJAX is bigger in scope than just XSLT, but they
    do use XSLT a lot).
    Andy Dingley, May 31, 2006
    #6
  7. Stan R.

    Stan R. Guest

    Stan R. wrote:
    > Peter Flynn wrote:
    >> Stan R. wrote:
    >>> Hi. I'm an old programmer whose been finally reading up on xml the
    >>> past week. The concepts of xml, dtd, and xsl seem pretty straight
    >>> forward to me. I understand that xsl (as xslt for transformations)
    >>> can be used to transform xml data from an xml document into another
    >>> document, as specified in the templates.
    >>>
    >>> One of the best examples I've seen by far is transforming a given
    >>> xml doc into html.
    >>>
    >>> But where I seem to be getting stuck in the mud is how to really
    >>> apply xml documents. I know they can be used as data holders and
    >>> config files for regular applications. But how do you use it more
    >>> directly, to, say, generate a webpage from an xml doc.

    >>
    >> You can write an XSLT transformation to do this, as you already
    >> mention in the previous paragraph.
    >>
    >>> Also (and this is kind of what I'm really getting at) is, is it
    >>> possible to write web pages, so to speak, using xml and xslt. I
    >>> noticed that such applications like Front Page 2003 (I sometimes use
    >>> it as my html editor) let you make xml documents.

    >>
    >> It's possible, but support for in-browser XML and XSLT is patchy.
    >> Server-side transformation is strongly recommended.
    >>
    >>> From what I can see, I can easily make an .xml, .dtd, and .xslt
    >>> files in a folder somewhere in the document root on my web server,
    >>> but what I TRULY don't understand is how do I actually "call" the
    >>> xslt (since it does the actual transformation) from the web browser?

    >>
    >> See the FAQ: http://xml.silmaril.ie/authors/style/
    >>
    >>> Does it need to be
    >>> "called" from an html document, or what? This is what I'm most
    >>> confused on, and thanks for any help clearing up the waters.

    >>
    >> The stylesheet has to be referenced in the XML document. The browser
    >> fetches it and applies it to perform the transformation.
    >>
    >>> (Also, any good real world examples for an xml+dtd+xslt would be
    >>> helpful too.)

    >>
    >> See the links in the FAQ (it's all done that way).
    >> http://xml.silmaril.ie/admin/availability/

    >
    > Thank you, this is more what I was after, the server side aspect
    > (though the other way, referencing xml files directly, how this was
    > done - which I feel really stupid for asking now given the answer was
    > staring me smack in the face - was also what I was interested in.)
    >
    > Many thanks to all.


    One more question if I may. From what I've gathered, usually you include
    the XSLT template right into your main xml doc you're working with, a
    la:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <?xml-stylesheet type="text/xsl" href="test.xsl"?>


    My question is, is it possible to have the main xml doc in one file
    (say, main.xml), but have a seperate xml file for the transformations
    (include both a XSLT and the main.xml document.)

    This would seem to make more sense to me, as you would have one file
    containing your xml data, and thne have seperate xml files, each
    including the main.xml, but different XSLT files.

    Say, you have one template for html output, and another for plain text,
    and another for some other format.

    From everything I've found online thus far, it seem including xml files
    in other xml files isn't a very clear topic, but it seems to me it
    should be an essential part if you want to keep things seperate and
    organized, unless I'm really missing something here.

    Thanks for any insight.

    --
    Stan
    Stan R., May 31, 2006
    #7
  8. Stan R. wrote:
    > One more question if I may. From what I've gathered, usually you include
    > the XSLT template right into your main xml doc you're working with, a
    > la:
    >
    > <?xml version="1.0" encoding="ISO-8859-1"?>
    > <?xml-stylesheet type="text/xsl" href="test.xsl"?>


    Not "include into", but "reference from".

    > My question is, is it possible to have the main xml doc in one file
    > (say, main.xml), but have a seperate xml file for the transformations
    > (include both a XSLT and the main.xml document.)


    That's exactly what the above achieves; the transformations are stored
    in test.xslt, references from your main XML document.

    If you mean "can I run different stylesheets at different times against
    the same XML" -- Yes, but then you have to use a system that lets you
    specify that pairing, rather than letting the XML file state which
    stylesheet it expects you'd want to run against it. That's easy to do
    when you're explicitly invoking an XSLT processor, less easy (because
    less standardized) when you're trying to use a browser.

    > From everything I've found online thus far, it seem including xml files
    > in other xml files isn't a very clear topic


    XInclude is clear, but not widely supported yet.... and not always the
    right answer.
    Joe Kesselman, May 31, 2006
    #8
  9. Stan R.

    Peter Flynn Guest

    Stan R. wrote:
    > One more question if I may. From what I've gathered, usually you include
    > the XSLT template right into your main xml doc you're working with, a
    > la:
    >
    > <?xml version="1.0" encoding="ISO-8859-1"?>
    > <?xml-stylesheet type="text/xsl" href="test.xsl"?>


    If you want to try and have it rendered in the browser, yes.
    Or if you simply want to record for others the location of a stylesheet.

    > My question is, is it possible to have the main xml doc in one file
    > (say, main.xml), but have a seperate xml file for the transformations
    > (include both a XSLT and the main.xml document.)


    In theory, yes, but not practically.

    > This would seem to make more sense to me, as you would have one file
    > containing your xml data, and thne have seperate xml files, each
    > including the main.xml, but different XSLT files.


    But then you'd have three separate copies of your document to maintain.
    That way madness lies.

    Why not just put three xml-stylesheet Processing Instructions into one
    copy of main.xml? Browsers don't honour that, at the moment, AFAIK,
    despite having been asked to support variant stylesheets for the best
    part of a decade.

    > Say, you have one template for html output, and another for plain text,
    > and another for some other format.
    >
    > From everything I've found online thus far, it seem including xml files
    > in other xml files isn't a very clear topic, but it seems to me it
    > should be an essential part if you want to keep things seperate and
    > organized, unless I'm really missing something here.


    No-one has ever asked to do it. The alternative is to have your three
    stylesheets, but run them on a dummy 1-line XML file, and use the
    document('main.xml') function to reference your main document, so that
    it gets included for processing. In XLST2, you don't even need the
    dummy file.

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/
    Peter Flynn, Jun 1, 2006
    #9
  10. Stan R.

    Stan R. Guest

    Peter Flynn wrote:
    > Stan R. wrote:
    >> One more question if I may. From what I've gathered, usually you
    >> include the XSLT template right into your main xml doc you're
    >> working with, a la:
    >>
    >> <?xml version="1.0" encoding="ISO-8859-1"?>
    >> <?xml-stylesheet type="text/xsl" href="test.xsl"?>

    >
    > If you want to try and have it rendered in the browser, yes.
    > Or if you simply want to record for others the location of a
    > stylesheet.


    But if you want to use multiple style sheets for one xml, it maybe
    better to perhaps leave a simple comment <!-- for HTML, use
    test_html.xsl --> ... And just use an xslt processor (xsltproc.) I
    assume this would be a good way?

    >> My question is, is it possible to have the main xml doc in one file
    >> (say, main.xml), but have a seperate xml file for the transformations
    >> (include both a XSLT and the main.xml document.)

    >
    > In theory, yes, but not practically.
    >
    >> This would seem to make more sense to me, as you would have one file
    >> containing your xml data, and thne have seperate xml files, each
    >> including the main.xml, but different XSLT files.

    >
    > But then you'd have three separate copies of your document to
    > maintain. That way madness lies.


    No no no, one main xml with the actual data/layout, and one dtd or xsd,
    and then seperate xsl files containing differnet templates for different
    things, which I've discovered xsltproc does a good job of. For instance:

    $ xmllint --noout --schema test.xsd test.xml
    test.xml validates

    $ xsltproc -o test.html test_html.xsl test.xml
    $ xsltproc -o test.foo test_foo.xsl test.xml
    $ xsltproc -o test.bar test_bar.xsl test.xml
    ....

    > Why not just put three xml-stylesheet Processing Instructions into one
    > copy of main.xml? Browsers don't honour that, at the moment, AFAIK,
    > despite having been asked to support variant stylesheets for the best
    > part of a decade.
    >
    >> Say, you have one template for html output, and another for plain
    >> text, and another for some other format.
    >>
    >> From everything I've found online thus far, it seem including xml
    >> files in other xml files isn't a very clear topic, but it seems to
    >> me it should be an essential part if you want to keep things
    >> seperate and organized, unless I'm really missing something here.

    >
    > No-one has ever asked to do it. The alternative is to have your three
    > stylesheets, but run them on a dummy 1-line XML file, and use the
    > document('main.xml') function to reference your main document, so that
    > it gets included for processing. In XLST2, you don't even need the
    > dummy file.


    How do you use the document('main.xml') ?

    --
    Stan
    Stan R., Jun 8, 2006
    #10
  11. Stan R.

    Peter Flynn Guest

    Stan R. wrote:
    > How do you use the document('main.xml') ?


    eg <xsl:apply-templates select="document('myfile.xml')/some/place"/>

    You just need templates which will handle the nodes that XSLT will
    encounter at /some/place/ onwards.

    ///Peter
    Peter Flynn, Jun 10, 2006
    #11
    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. Amir
    Replies:
    3
    Views:
    593
  2. nc
    Replies:
    1
    Views:
    492
    nice.guy.nige
    Feb 3, 2005
  3. Replies:
    2
    Views:
    335
  4. Jeannie
    Replies:
    15
    Views:
    883
    Jeannie
    Aug 30, 2005
  5. =?Utf-8?B?TFc=?=
    Replies:
    8
    Views:
    414
    =?Utf-8?B?TFc=?=
    Apr 25, 2007
Loading...

Share This Page