Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Re: Newbie, HTML calling XSLT

Reply
Thread Tools

Re: Newbie, HTML calling XSLT

 
 
Peter Flynn
Guest
Posts: n/a
 
      08-20-2005
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

 
Reply With Quote
 
 
 
 
dingbat@codesmiths.com
Guest
Posts: n/a
 
      08-22-2005

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
<xslutput ... /> )

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.

 
Reply With Quote
 
 
 
 
Peter Flynn
Guest
Posts: n/a
 
      08-22-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
> <xslutput ... /> )


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

 
Reply With Quote
 
dingbat@codesmiths.com
Guest
Posts: n/a
 
      08-23-2005

Peter Flynn wrote:
> (E-Mail Removed) 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.

 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      08-23-2005
(E-Mail Removed) wrote:

>
> Peter Flynn wrote:
>> (E-Mail Removed) 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Newbie, HTML calling XSLT dingbat@codesmiths.com XML 0 08-23-2005 08:48 AM
Re: Newbie, HTML calling XSLT Martin Honnen XML 0 08-20-2005 12:16 PM
ANN: New low-cost XML Editor, XSLT Editor, XSLT Debugger, DTD/Schema Editor Stylus Studio Java 0 08-03-2004 03:53 PM
xslt alone or xslt/java for static site? ted XML 1 01-26-2004 10:41 AM
[XSLT]Passing values from Javascript to a XSLT variable Benjamin Hillsley XML 3 09-25-2003 04:50 AM



Advertisments