Re: Newbie, HTML calling XSLT

Discussion in 'XML' started by Peter Flynn, Aug 21, 2005.

  1. Peter Flynn

    Peter Flynn Guest

    Clive wrote:

    > Hi
    >
    > I am new to XML, XSLT and know little HTML - so this may be a very
    > naive question.
    >
    > For an exercise, I would like to write a simple HTML page that calls
    > XSLT and passes it parameters.


    You can't do this with [original] HTML -- your page must be XHTML (or any
    other flavour of XML) because XSLT 1.0 only processes XML. The original
    HTML is written in SGML, not XML, and that won't work with XSLT.

    The method of invoking an XSLT stylesheet from within an XML file is to use
    a Processing Instruction at the top of the file, after the XML Declaration
    and the Document Type Declaration but before the root element, eg

    <?xml version="1.0"?>
    <!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <?xml-stylesheet href="mystylesheet.xsl" type="text/xsl"?>
    <html>
    <head>
    <title>...etc etc

    But I don't know any way of passing parameters into a stylesheet by this
    method (maybe there is, but I just haven't come across it yet). You can do
    it with Javascript, and doubtless with any number of other embedded tools
    (eg VBscript), and it can be done on the server side if you run an XML
    server like Cocoon or AxKit or PropelX, and with any number of server-side
    scripting languages like Perl, PHP, Python, Tcl, etc as you rightly guess
    below.

    > I know how to "accept" parameters into xslt and I have tested this
    > using Oxygen XML editor. It is the HTML to XSLT connection I don't
    > understand.
    >
    > Can this "link" be achieved with pure (X)HTML or do I need some
    > programming language like Perl or php to achieve this?


    The acceptance of parameters requires the intervention of a program of some
    kind: neither HTML not XHTML have facilities for doing this because they are
    not themselves programming languages.

    ///Peter
    Peter Flynn, Aug 21, 2005
    #1
    1. Advertising

  2. Peter Flynn

    Guest

    Peter Flynn wrote:
    > Clive wrote:
    >
    > > For an exercise, I would like to write a simple HTML page that calls
    > > XSLT and passes it parameters.

    >
    > You can't do this with [original] HTML -- your page must be XHTML (or any
    > other flavour of XML) because XSLT 1.0 only processes XML. The original
    > HTML is written in SGML, not XML, and that won't work with XSLT.


    That's a misleading statement. You can't "work with XSLT" from within
    HTML because you need scripting (HTML isn't a programming language),
    not because it's not XML (and so would need XHTML). If you have
    JavaScript and some XML scripting tools, then you can use XSLT from
    _within_ HTML perfectly well.

    You can't process HTML as _input_ to XSLT because it's not XML -- but
    that's a totally different question.

    You can make HTML from XSLT easily, because this was an obvious
    use-case for XSLT and so there's an option to support it (look at
    <xsl:eek:utput ... /> )

    As for the "scripting" case, then this works very well (and with HTML),
    but you need to have a "modern" browser. It may work for intranets or
    local demonstrations, but you should be careful putting such a thing
    onto the public web and expecting it to work for everyone.
    , Aug 22, 2005
    #2
    1. Advertising

  3. Peter Flynn

    Peter Flynn Guest

    wrote:

    >
    > Peter Flynn wrote:
    >> Clive wrote:
    >>
    >> > For an exercise, I would like to write a simple HTML page that calls
    >> > XSLT and passes it parameters.

    >>
    >> You can't do this with [original] HTML -- your page must be XHTML (or any
    >> other flavour of XML) because XSLT 1.0 only processes XML. The original
    >> HTML is written in SGML, not XML, and that won't work with XSLT.

    >
    > That's a misleading statement.


    I could probably have phrased it better.

    > You can't "work with XSLT" from within
    > HTML because you need scripting (HTML isn't a programming language),
    > not because it's not XML (and so would need XHTML).


    That too, but the basic reason it won't work is that XSLT will gag if you
    feed it an SGML HTML document that doesn't happen -- accidentally or by
    design -- also to be well-formed XHML (eg fully-normalized and without
    SGML-format EMPTY elements). Scripting doesn't enter into it at this stage.

    > If you have
    > JavaScript and some XML scripting tools, then you can use XSLT from
    > _within_ HTML perfectly well.
    >
    > You can't process HTML as _input_ to XSLT because it's not XML -- but
    > that's a totally different question.


    If by the first statement you mean "use Javascript and some XML scripting
    tools to make the HTML into well-formed XHTML so that XSLT can process it",
    then yes (and that may be what the OP was looking for but not asking
    directly): otherwise the two statements above are in direct contradiction to
    each other.

    Can you give me an example of the first one?

    Processing HTML as _input_ to XSLT because it's not XML was precisely what
    was implied by the OP's question.

    > You can make HTML from XSLT easily, because this was an obvious
    > use-case for XSLT and so there's an option to support it (look at
    > <xsl:eek:utput ... /> )


    You mean "make HTML from X[HT]ML using XSLT"? Sure. But that wasn't what
    the OP asked.

    > As for the "scripting" case, then this works very well (and with HTML),
    > but you need to have a "modern" browser. It may work for intranets or
    > local demonstrations, but you should be careful putting such a thing
    > onto the public web and expecting it to work for everyone.


    Absolutely.

    ///Peter
    Peter Flynn, Aug 22, 2005
    #3
  4. Peter Flynn

    Guest

    Peter Flynn wrote:
    > wrote:


    > > You can't "work with XSLT" from within
    > > HTML because you need scripting (HTML isn't a programming language),
    > > not because it's not XML (and so would need XHTML).

    >
    > That too, but the basic reason it won't work is that XSLT will gag if you
    > feed it an SGML HTML document that doesn't happen -- accidentally or by
    > design -- also to be well-formed XHML (eg fully-normalized and without
    > SGML-format EMPTY elements). Scripting doesn't enter into it at this stage.



    The OP asked this:
    >:> For an exercise, I would like to write a simple HTML page that calls
    >:> XSLT and passes it parameters.


    That's a request to call XSLT tools from within HTML, not to feed HTML
    _to_ XSLT tools.
    , Aug 23, 2005
    #4
  5. Peter Flynn

    Peter Flynn Guest

    wrote:

    >
    > Peter Flynn wrote:
    >> wrote:

    >
    >> > You can't "work with XSLT" from within
    >> > HTML because you need scripting (HTML isn't a programming language),
    >> > not because it's not XML (and so would need XHTML).

    >>
    >> That too, but the basic reason it won't work is that XSLT will gag if you
    >> feed it an SGML HTML document that doesn't happen -- accidentally or by
    >> design -- also to be well-formed XHML (eg fully-normalized and without
    >> SGML-format EMPTY elements). Scripting doesn't enter into it at this
    >> stage.

    >
    >
    > The OP asked this:
    >>:> For an exercise, I would like to write a simple HTML page that calls
    >>:> XSLT and passes it parameters.

    >
    > That's a request to call XSLT tools from within HTML, not to feed HTML
    > _to_ XSLT tools.


    I undertood this to mean Clive wanted a HTML page which invoked XSLT with
    parameters to process the HTML on that page itself.

    Otherwise all he wants is a link to an XML page which uses XSLT to process
    itself (and I warned that I had never seen this done with parameters unless
    a script was involved); or a link to an external engine like Cocoon.

    My reply answered both interpretations.

    ///Peter
    Peter Flynn, Aug 23, 2005
    #5
    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. Stylus Studio
    Replies:
    0
    Views:
    651
    Stylus Studio
    Aug 3, 2004
  2. Benjamin Hillsley
    Replies:
    3
    Views:
    1,675
    Dimitre Novatchev
    Sep 25, 2003
  3. ted
    Replies:
    1
    Views:
    619
    Laurens
    Jan 26, 2004
  4. Martin Honnen

    Re: Newbie, HTML calling XSLT

    Martin Honnen, Aug 20, 2005, in forum: XML
    Replies:
    0
    Views:
    384
    Martin Honnen
    Aug 20, 2005
  5. Replies:
    0
    Views:
    397
Loading...

Share This Page