By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

XML over CSS

P: n/a
Hi,

I am a relatively new PHP programmer and I am familiar with programming
logic of web sites. I now want to get a good grasp of content and
presentation. I am trying to figure out if I should focus on XML and XSL
or CSS.

Can XML and XSL be used to show content to a browser? or can only HTML do
that?

I am thinking that if I could do everything in XML and XSL that I could do
using CSS that I might want to focus on XML and XSL because I can also do
other things with XML and XSL like Web services.

But, is XML and XSL harder to use than CSS and HTML? Signifigantly harder?

I am planning on building large content management type Web applications.

Your humble opinion is much appreciated (YHOIMA)
Jul 17 '05 #1
Share this Question
Share on Google+
16 Replies


P: n/a
Mudge wrote:
I am a relatively new PHP programmer and I am familiar with programming
logic of web sites. I now want to get a good grasp of content and
presentation. I am trying to figure out if I should focus on XML and XSL
or CSS.

Can XML and XSL be used to show content to a browser? or can only HTML do
that?

I am thinking that if I could do everything in XML and XSL that I could do
using CSS that I might want to focus on XML and XSL because I can also do
other things with XML and XSL like Web services.

But, is XML and XSL harder to use than CSS and HTML? Signifigantly
harder?

I am planning on building large content management type Web applications.

Your humble opinion is much appreciated (YHOIMA)


BTW - you should crosspost not multipost so that when we reply it goes to
all the relevant groups... anyway, here is my answer to your multiposted
question at alt.php

XSL is used to transform XML into another format. In the case of a website
you are transforming the source XML into HTML/XHTML. Whether or not you use
CSS for style and/or positioning isn't actually relevant to your choice of
XML/XSL.

The nice thing with using XSL to create HTML is that it ensures you close
all your tags (eg <br /> <input type="text" /> instead of <br> and <input
type="text">) which helps with making your pages XHTML compliant (this
alone does not make them compliant, but it helps out).

Another nice thing is it helps move the presentation layer of your
application away from the business logic, if you are wanting to create a
tiered/layered appplication solution.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #2

P: n/a
Chris Hope wrote:
Mudge wrote:
I am a relatively new PHP programmer and I am familiar with programming
logic of web sites. I now want to get a good grasp of content and
presentation. I am trying to figure out if I should focus on XML and XSL
or CSS.

Can XML and XSL be used to show content to a browser? or can only HTML
do that?

I am thinking that if I could do everything in XML and XSL that I could
do using CSS that I might want to focus on XML and XSL because I can also
do other things with XML and XSL like Web services.

But, is XML and XSL harder to use than CSS and HTML? Signifigantly
harder?

I am planning on building large content management type Web applications.

Your humble opinion is much appreciated (YHOIMA)


BTW - you should crosspost not multipost so that when we reply it goes to
all the relevant groups... anyway, here is my answer to your multiposted
question at alt.php

XSL is used to transform XML into another format. In the case of a website
you are transforming the source XML into HTML/XHTML. Whether or not you
use CSS for style and/or positioning isn't actually relevant to your
choice of XML/XSL.

The nice thing with using XSL to create HTML is that it ensures you close
all your tags (eg <br /> <input type="text" /> instead of <br> and <input
type="text">) which helps with making your pages XHTML compliant (this
alone does not make them compliant, but it helps out).

Another nice thing is it helps move the presentation layer of your
application away from the business logic, if you are wanting to create a
tiered/layered appplication solution.


Please explain how it helps move the presentation layer away from the
business logic.


Jul 17 '05 #3

P: n/a
Mudge wrote:
Another nice thing is it helps move the presentation layer of your
aabilityion away from the business logic, if you are wanting to create a
tiered/layered appplication solution.


Please explain how it helps move the presentation layer away from the
business logic.


Let's say you have a basic 3 tier/layer system. (There are other models
which feature additional tiers at different places, and allow for more
abstraction from the database using database objects. Interesting stuff but
beyond the scope of this post).

The first tier is database access. You might use something like the PEAR
library to handle your database stuff.

In the middle tier you have your business logic, which handles stuff like
session management, data manipulation, calculations etc. Using an XML/XSL
model, you use this tier to construct the XML.

The 3rd tier handles the presentation of what's been done in the middle tier
by turning it into a web page. Using the XML/XSL model we're manipulating
the data given to us by an XML string with an XSL file at this tier.

XSL is more of a presentation language than a programming language. It has
some ability to loop and call functions etc but it's mainly good at turning
XML into another format, in this case HTML.

My own site uses this exact tiered approach. Data is fetched from the
database using calls through the PEAR library and manipulated into XML
through the use of the XML_Tree package -
http://pear.php.net/manual/en/package.xml.xml-tree.php

I then use XSL stylesheets to turn the XML into HTML on the server-side
which is then sent to the browser. Actual page layout is done using CSS
positioning with a style sheet. (Note that this was the first site I used
CSS positioning for and it needs a bit of work when ever I get time to...)

There was someone else who posted within the last week or so who uses a
similar tiered approach with XML/XSL.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #4

P: n/a
Chris Hope wrote:
Mudge wrote:
Another nice thing is it helps move the presentation layer of your
aabilityion away from the business logic, if you are wanting to create a
tiered/layered appplication solution.


Please explain how it helps move the presentation layer away from the
business logic.


Let's say you have a basic 3 tier/layer system. (There are other models
which feature additional tiers at different places, and allow for more
abstraction from the database using database objects. Interesting stuff
but beyond the scope of this post).

The first tier is database access. You might use something like the PEAR
library to handle your database stuff.

In the middle tier you have your business logic, which handles stuff like
session management, data manipulation, calculations etc. Using an XML/XSL
model, you use this tier to construct the XML.

The 3rd tier handles the presentation of what's been done in the middle
tier by turning it into a web page. Using the XML/XSL model we're
manipulating the data given to us by an XML string with an XSL file at
this tier.

XSL is more of a presentation language than a programming language. It has
some ability to loop and call functions etc but it's mainly good at
turning XML into another format, in this case HTML.

My own site uses this exact tiered approach. Data is fetched from the
database using calls through the PEAR library and manipulated into XML
through the use of the XML_Tree package -
http://pear.php.net/manual/en/package.xml.xml-tree.php

I then use XSL stylesheets to turn the XML into HTML on the server-side
which is then sent to the browser. Actual page layout is done using CSS
positioning with a style sheet. (Note that this was the first site I used
CSS positioning for and it needs a bit of work when ever I get time to...)

There was someone else who posted within the last week or so who uses a
similar tiered approach with XML/XSL.


Thank you. Do you think that generating XML and then using XSL to change it
into HTML and then using CSS for page layout and display -- do you think
this makes it easier to separate presentation from business logic than just
using HTML and CSS?

Jul 17 '05 #5

P: n/a
Mudge wrote:
Thank you.**Do*you*think*that*generating*XML*and*then*us ing*XSL*to*change
it into HTML and then using CSS for page layout and display -- do you
think this makes it easier to separate presentation from business logic
than just using HTML and CSS?


It depends how you code your PHP. But generally when people code the HTML
output in the PHP you often end up with a lot of HTML and PHP being mixed
up together with database calls in the middle of the HTML output. There's
not necessarily anything wrong with this (and I've done it plenty of times
in the past) but it is nice to separate that stuff from the output. Using
XML/XSL enforces the separation.

There are other methods though, such as using a templated solution like
Smarty (I've never used it myself but seen it mentioned here before).

A lot of your decision really comes down to how much you want to have to
learn. If you choose XML & XSL to do the presentation layer then you're
going to have to learn XSL as well as PHP. An excellent XSL reference book
(if you decide to learn it) is http://tinyurl.com/36jq9

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #6

P: n/a
"Chris Hope" <bl*******@electrictoolbox.com> wrote in message
news:10************@216.128.74.129...
Mudge wrote:
I am a relatively new PHP programmer and I am familiar with programming
logic of web sites. I now want to get a good grasp of content and
presentation. I am trying to figure out if I should focus on XML and XSL or CSS.

Can XML and XSL be used to show content to a browser? or can only HTML do that?

I am thinking that if I could do everything in XML and XSL that I could do using CSS that I might want to focus on XML and XSL because I can also do other things with XML and XSL like Web services.

But, is XML and XSL harder to use than CSS and HTML? Signifigantly
harder?

I am planning on building large content management type Web applications.
Your humble opinion is much appreciated (YHOIMA)
BTW - you should crosspost not multipost so that when we reply it goes to
all the relevant groups... anyway, here is my answer to your multiposted
question at alt.php

XSL is used to transform XML into another format. In the case of a website
you are transforming the source XML into HTML/XHTML. Whether or not you

use CSS for style and/or positioning isn't actually relevant to your choice of
XML/XSL.

The nice thing with using XSL to create HTML is that it ensures you close
all your tags (eg <br /> <input type="text" /> instead of <br> and <input
type="text">) which helps with making your pages XHTML compliant (this
alone does not make them compliant, but it helps out).

Another nice thing is it helps move the presentation layer of your
application away from the business logic, if you are wanting to create a
tiered/layered appplication solution.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/


The not so nice things about using XSL are that it's not always very stable,
especially when the documents are large, not widely support by ISPs, and
that it's complex as hell. And when you use XML, you place an extra burden
on yourself to generate a valid document. If you forget to escape a single
ampersand, the transform engine will choke.
Jul 17 '05 #7

P: n/a
Chung Leong wrote:
The not so nice things about using XSL are that it's not always very
stable, especially when the documents are large, not widely support by
ISPs, and that it's complex as hell. Ah yes, I forgot to mention those points.

I've found large documents just don't work at all. I have a section on my
site with manpages formatted into HTML and I can't put the larger ones
online because the parser dies.

And if the appropriate extensions aren't compiled into PHP you won't be able
to use them. Some providers will have them but I would imagine most don't,
which limits your choice when it comes to hosting (unless you have your own
server, of course).
And when you use XML, you place an
extra burden on yourself to generate a valid document. If you forget to
escape a single ampersand, the transform engine will choke.


I don't find that a problem though, as it means something external to you is
checking to ensure you are creating valid XHTML.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #8

P: n/a

"Mudge" <ma******@hotmail.com> wrote in message
news:8WjIc.53806$JR4.34137@attbi_s54...
Hi,

I am a relatively new PHP programmer and I am familiar with programming
logic of web sites. I now want to get a good grasp of content and
presentation. I am trying to figure out if I should focus on XML and XSL
or CSS.

Can XML and XSL be used to show content to a browser? or can only HTML do
that?
All websites are output in HTML. To be efficient you should also use CSS.
You can generate your HTML directly from within a PHP script, or your PHP
script could generate an XML document which is then transformed into HTML by
using the contents of an XSL file.
I am thinking that if I could do everything in XML and XSL that I could do
using CSS that I might want to focus on XML and XSL because I can also do
other things with XML and XSL like Web services.
XML/XSL is not used "instead of" CSS, it is used "as well as".
But, is XML and XSL harder to use than CSS and HTML? Significantly harder?

XML and XSL are additional things to learn. XSL is actually a scripting
language is its own right with its own syntax and its own foibles. As such
it is a new language that you have to learn.

There are plenty of resources on the web which give information and/or
tutorials concerning XML and XSL. If you visit
http://www.tonymarston.co.uk/xml-xsl/index.html you will see some articles I
have written on the subject.
I am planning on building large content management type Web applications.

Your humble opinion is much appreciated (YHOIMA)


I use XML and XSL within my PHP application to separate presentation from
business logic. My framework/infrastructure is actually a combination of the
3 tier architecture and the Model-View-Controller design pattern. If you
visit http://www.tonymarston.co.uk/php-mysql/index.html you will see some
articles I have written on the subject.

I also have a sample application which uses my framework which you can run
online. You can also download the code and run it locally if you want to see
how it works. Take a look at
http://www.tonymarston.net/php-mysql...plication.html for details.

Hope this helps.

--
Tony Marston

http://www.tonymarston.net

Jul 17 '05 #9

P: n/a


Can XML and XSL be used to show content to a browser? or can only HTML
do that?


All websites are output in HTML.


Are they? I thought IE6 and Moz et al supported XML/XSLT natively? I'm
sure I've seen sites using this..

I am planning on building large content management type Web
applications.

Your humble opinion is much appreciated (YHOIMA)


Personally I would get your application to write out XHTML with sufficient
use of inheritable CSS classes and DIV tags that CSS could be used to
style it in any way the administrator wishes.
Martin
Jul 17 '05 #10

P: n/a
Martin Lucas-Smith wrote:
Can XML and XSL be used to show content to a browser? or can only
HTML do that?


All websites are output in HTML.


Are they? I thought IE6 and Moz et al supported XML/XSLT natively? I'm
sure I've seen sites using this..


What Tony meant is that what browsers receive is HTML; even if you send the
XML from the server and accompany it by XSL for the browser to transform it,
XSLT still transforms it into HTML before displaying it.

However, it doesn't have to be so. It is quite possible to serve a page as
pure XML and use CSS to give it appearance; actually, this is as XML was
originally intended, to replace HTML completely. As we know, that didn't
happen, but still the basic difference between XHTML and pure XML is that
browsers have defined default appearance for most XHTML elements.

As it comes to XSLT, it is designed to convert XML into any kind of
text-based output, so you can get another XML, XHTML, HTML, CSV or simple
plain text from your XML.

I guess that the OP is trying to decide what to use, client-side, to give
appearance to his content, outputted as XML. As someone else in the thread
mentioned, letting the client do the job is not really a good idea, as the
browser support for any of the above technologies is still far from ideal.

Probably the best approach is to create content as XML and then convert it
by XSLT, server-side, into HTML, possibly setting the appearance by CSS. The
downside of this approach might be (for someone) that you might need to know
a whole bunch of languages: PHP for server-side processing, HTML/HTML and
CSS for browser display, SQL for working with the database, XSLT and XPath
for working with XML and even Javascript for possible client-side
processing. (I didn't mention XML because there isn't really that much to
learn about it, being a meta-language; however, one would still be quite
familiar with XML vocabilaries used in the application, which might involve
learning DTD or XSchema.)

For good tutorials on most of the above technologies, see
http://www.w3schools.com

Berislav

--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.
Jul 17 '05 #11

P: n/a

"Martin Lucas-Smith" <mv***@cam.ac.uk> wrote in message
news:Pi******************************@hermes-1.csi.cam.ac.uk...


Can XML and XSL be used to show content to a browser? or can only HTML
do that?


All websites are output in HTML.


Are they? I thought IE6 and Moz et al supported XML/XSLT natively? I'm
sure I've seen sites using this..


A website may contain nothing but XML documents, but these are actually
transformed into (X)HTML within the client browser. If you use the "View
Source" option you will see a reference to both an XML and an XSL file. The
disadvantage of performing the XSL transformation within the client browser
is that it relies on the fact that the client machine contains the relevant
software. The advantage of server-side transformations is you only need the
software on te server, which is under your control. Once the server has
transformed the XML into (X)HTML and sent it over the internet to the client
device all that it knos is that it is receiving an (X)HTML document - it
hasn't the foggiest idea of how it was created.

Client-side transformations cannot be done with browsers which do not
support this option, which is why it is not a good idea to use this option
on internet sites which may be accessed by users with non-XSL capable
browsers. Even with IE the transformation engine has been updated several
times, so if a site has been built to use the latest version and the client
does not have that version then the results cannot be guaranteed.
I am planning on building large content management type Web
applications.

Your humble opinion is much appreciated (YHOIMA)


Personally I would get your application to write out XHTML with sufficient
use of inheritable CSS classes and DIV tags that CSS could be used to
style it in any way the administrator wishes.


Good advice. By putting all style into a CSS document it makes it much
easier to change the style of a whole website by changing a single CSS
document.

--
Tony Marston

http://www.tonymarston.net
Jul 17 '05 #12

P: n/a
On Mon, 12 Jul 2004 16:44:51 +1200, Chris Hope wrote:
A lot of your decision really comes down to how much you want to have to
learn. If you choose XML & XSL to do the presentation layer then you're
going to have to learn XSL as well as PHP. An excellent XSL reference book
(if you decide to learn it) is http://tinyurl.com/36jq9

Same book at BookPool.com is only $17.25 (compared to Amazon's $23.79):

http://www.bookpool.com/.x/abm88doyq0/sm/0764543814
I just like to mention BookPool when others suggest reference material.
For me they've always been cheaper and very reliable.
Jul 17 '05 #13

P: n/a
Benny Hill wrote:
I just like to mention BookPool when others suggest reference material.
For me they've always been cheaper and very reliable.


That's great. Thanks for that. Will check them out when I need to buy new
books.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #14

P: n/a

"Chris Hope" <bl*******@electrictoolbox.com> wrote in message
news:10*************@216.128.74.129...
It depends how you code your PHP. But generally when people code the HTML
output in the PHP you often end up with a lot of HTML and PHP being mixed
up together with database calls in the middle of the HTML output. There's
not necessarily anything wrong with this (and I've done it plenty of times
in the past) but it is nice to separate that stuff from the output. Using
XML/XSL enforces the separation.


Well, if you look at it from the another prospective, a technology that
forces you to do things in a certain way takes away flexibility.

It's worth remember that while it's nice to separate logic from
presentation, that in itself is not the goal, or even a goal. The objective
of programming is to create software that does something useful. An obvious
truth but a surprisingly large number of those in our field seem not to
understand it. A lot of beginners, espeically, suffer from what I call the
"CS syndrome." They just sit around trying to come up with code that
demostrates a particular technique, technology, or principle--precisely the
kind of code that you find in programming books.
--
Obey the Clown - http://www.conradish.net/bobo/
Jul 17 '05 #15

P: n/a

"Chung Leong" <ch***********@hotmail.com> wrote in message
news:sN********************@comcast.com...

"Chris Hope" <bl*******@electrictoolbox.com> wrote in message
news:10*************@216.128.74.129...
It depends how you code your PHP. But generally when people code the HTML
output in the PHP you often end up with a lot of HTML and PHP being mixed
up together with database calls in the middle of the HTML output. There's
not necessarily anything wrong with this (and I've done it plenty of timesin the past) but it is nice to separate that stuff from the output. Using
XML/XSL enforces the separation.
Well, if you look at it from the another prospective, a technology that
forces you to do things in a certain way takes away flexibility.


That is true, but there are supposed to be trade-offs. In order to provide a
RAD (Rapid Application Development) environment you need to make as much use
of reusable code as possible. This gives you speed of development as you
don't have to rewrite the same code each time. The trade-off is that when
you use a resuable module you are stuck with what that reusable module does
or the way that it does it. If you want to do something different to have to
write a new module. So there is a trade-off between reusability and
flexibility. The trick is to provide modules that combine both, but not many
programmers can do that.
It's worth remember that while it's nice to separate logic from
presentation, that in itself is not the goal, or even a goal. The objective of programming is to create software that does something useful. An obvious truth but a surprisingly large number of those in our field seem not to
understand it. A lot of beginners, espeically, suffer from what I call the
"CS syndrome." They just sit around trying to come up with code that
demostrates a particular technique, technology, or principle--precisely the kind of code that you find in programming books.


How true. What is even worse is that some senior programmers follow a
technique or paradigm with almost religious zeal. They think that their way
of doing it is "the only true way" and that anyone who attempts to adopt an
alternative method is a heretic. Their approach is dogmatic (follow the
rules and damn the result) whereas mine is pragmatic (achieve a result
regardless of the rules).

--
Tony Marston

http://www.tonymarston.net

Jul 17 '05 #16

P: n/a
"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message
news:cd*******************@news.demon.co.uk...
That is true, but there are supposed to be trade-offs. In order to provide a RAD (Rapid Application Development) environment you need to make as much use of reusable code as possible. This gives you speed of development as you
don't have to rewrite the same code each time. The trade-off is that when
you use a resuable module you are stuck with what that reusable module does or the way that it does it. If you want to do something different to have to write a new module. So there is a trade-off between reusability and
flexibility. The trick is to provide modules that combine both, but not many programmers can do that.
Reusability is great of course. What people consistently fail to understand
is that it takes considerable effort to make code reusable. That includes
testing and documentation. I simply love the application framework in
Delphi, for example. And even some of Microsoft's stuff impresses me
sometimes. In these instances the companies made serious investment into
creating APIs that are programmer-friendly. That was the focus of the
designers/programmers. The notion that some alone programmer, while coding
some website, can somehow come up high-quality reusable code is unrealistic
and contrary to my own experience
How true. What is even worse is that some senior programmers follow a
technique or paradigm with almost religious zeal. They think that their way of doing it is "the only true way" and that anyone who attempts to adopt an alternative method is a heretic. Their approach is dogmatic (follow the
rules and damn the result) whereas mine is pragmatic (achieve a result
regardless of the rules).


Form follows function. The end ususally suggests the means. The trick is to
know what you're trying to accomplish and not lose focus on that. Far too
many programmers develope in a backward manner, coming up with the solution
before they know what the requirements are. Not unlike the actions of a
certain head of state: "we have to invade Iraq! Why? Because invading Iraq
is the thing to do."
Jul 17 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.