473,320 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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
May 30 '06 #1
10 1526
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 30 '06 #2
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

May 30 '06 #3
dh*******@gmail.com 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
May 31 '06 #4
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
May 31 '06 #5
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).

May 31 '06 #6
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
May 31 '06 #7
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/
Jun 1 '06 #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.
Jun 3 '06 #9
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
Jun 8 '06 #10
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

Jun 10 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: {AGUT2}=IWIK= | last post by:
Hello all, It's my fisrt post here and I am feeling a little stupid here, so go easy.. :) (Oh, and I've spent _hours_ searching...) I am desperately trying to read in an ASCII...
21
by: Jason Heyes | last post by:
I want to allow objects of my class to be read from an input stream. I am having trouble with the implementation. Here are the different approaches I have tried: // Version 1.0 - Default...
123
by: C# Learner | last post by:
I've had enough of C#. I've had enough of using parentheses for every 'if' statement. I've had enough of having to mix assignment of return value of methods with flow control, making writing code...
4
by: DraguVaso | last post by:
Hi, I have files I need to read, which contains records with a variable lenght. What I need to do is Copy a Part of such a File to a new File, based on the a Begin- and End-record. I used...
6
by: DraguVaso | last post by:
Hi, I have files I need to read, which contains records with a variable lenght. What I need to do is Copy a Part of such a File to a new File, based on the a Begin- and End-record. I used...
3
by: nsh | last post by:
mailing.database.mysql, comp.lang.php subject: does "LOAD DATA" EVER work?!? I've tried EVERYTHING! version info: my isp is running my web page on a linux box with php ver. 4.4.1 according to...
2
by: ChrisM | last post by:
I've got a medium sized project written in C# for .NET1.1 the project is live, but still under constant development. There seems to be a lot of new stuff in .NET2.0 that I'm missing out on, and now...
22
by: gillisct | last post by:
I'd like to say I have a basic control of the C language. Is there any reccomended reading upon completion of K&R? Are there any projects someone new to C could study/watch over/ and eventually...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.