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

S

Stan R.

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.)
 
D

dhanvanth

Stan said:
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
 
P

Peter Flynn

Stan said:
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
 
S

Stan R.

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




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.


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.
 
S

Stan R.

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


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


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


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


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.
 
A

Andy Dingley

Stan said:
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).
 
S

Stan R.

Stan said:
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.
 
J

Joe Kesselman

Stan said:
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.
 
P

Peter Flynn

Stan said:
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
 
S

Stan R.

Peter said:
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?
In theory, yes, but not practically.


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.


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') ?
 
P

Peter Flynn

Stan said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top