Jump to content

XML and CSS


gawain
 Share

Recommended Posts

Hi everybody.I'd like to know something about XML, but before starting to read the tutorial, I was wondering if with a XML file I can obtain the same web page I can have with XHTML+CSS, or if working with xml implies a totally different final output.Thanks for any help

Link to comment
Share on other sites

When I am using XML...I make my layout in pure XHTML (and use CSS)...and I think about how I am going to apply my XML data to it. I then create my XSLT using my layout and apply all the XML data and wha-lah! it's a site!To style an XML use XSLT.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="html" omit-xml-declaration="yes" indent="yes"/><xsl:template match="/"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/><title>Untitled Document</title><link rel="stylesheet" type="text/css" href="YOURCSS.css" /><!--or like this:<style></style>--></head><body>Contents In here (just like XHTML)</body></html></xsl:template></xsl:stylesheet>

Just apply the XSLT to your XML and open the XML...and it will look like a "normal" XHTML page rather than a data tree....and then to make it even more exciting you can use a server side script (such as PHP or ASP) and really make it dynamic.

Link to comment
Share on other sites

Thanks a lot kvnmck18 for answering.I haven't any XHTML code.I'm just trying to understand if it is worthwhile learning xml or if itis something which is an alternative to XHTML + CSS.As far as I can understand it seems that XML enables me to do something which otherwise I couldn't do just with plain CSS and PHP; therefore it's worthwhile learning and investing time on it.Please, if you can confirm this.Thanks a lot

Link to comment
Share on other sites

Actually, both PHP and XSLT produce XHTML as their final output, so whatever you can achieve with XHTML, you can achieve the same in XSLT or PHP, but dynamically.The big difference in all is that XSLT stylesheets can be put under any S3L (see my signature), while XHTMLs assambled with PHP can run only under PHP. Not only that, but there may be version limitations as well (incompatabilities between version 4 and 5 for example). In the case of XSLT, only the S3L code needed to process XSLT will be rewritten.Scenario: I have a host that supports PHP4 and MySQL and decide that I have a lot of common components and stuff I'll need to generate dynamically.Solution 1: I decide to utilize the power of PHP4 for this. At some point, I find out I need a database, perhaps for common stuff, user input, etc. I decide to use MySQL, scince that is what my hosts supports. At some point, I decide I need something that only PHP5 has and that porting it to PHP4 would be really unefficient. I move on, expecting PHP to be backdraw compatable. But it's not. I need to rewrite the whole application. It would have gotten worse if I moved to ASP(.NET) or another database server.Solution 2: I use XSLT to generate the stuff dynamically and use XML as a database. PHP4 is used to send the XHTML ouput and pass parameters to XSLT in order to make it dynamic. I divide the whole thing into seveal XML files for efficiency's sake and use XSLT's power to "travel" between those files. I decide to move to PHP5. The only thing I have to rewrite is the PHP file that executes the transformation. This is significantly easier to do then rewriting the whole application. The situation stays the same if I decide to use ASP(.NET) and scince I use XML, XML is what remains my database. If a new version of XSLT comes out (FYI, there already is- XSLT2, but it's not supported in any S3L yet), I can still use my older one, as the XSLT file contains a version attribute, telling the XSLT processor that it needs to use the XSLT1 behaviour. When I think I'm ready for the newer versions of XSLT, I can change that attribute and/or rewrite the XSLT file(s) if needed. The same applies if a newer version of XML comes out.

Link to comment
Share on other sites

Thanks a lot Mr been_robot. :) I've read your answer quite carefully, so carefully that I've been reading around about xml, so that I'm seriously thinking of restarting everything about the site I had in mind.But if I can, one more question: which version of xml would you suggest, microsft xml (MSXML) or ... the other one?Thanks

Link to comment
Share on other sites

But if I can, one more question: which version of xml would you suggest, microsft xml (MSXML) or ... the other one?
Ah, now that's just the most beautiful part. That doesn't actually matter very much. Keep reading to find out why.First stop, you're not using "a different version of XML" but "a different XML parser/XSLT processor".XML is written in plain text. There is another application that needs to process it. That application is called "XML parser". MSXML is one such XML parser. Most, if not all XML parsers share the same set of features and read the XML file in the same manner, so if you need to migrate from one to another, you can do so without any worries for compatability. The biggest differences between them are speed and the way in which you can use them (the so called "API"s).Almost all of the above applies to XSLT too. It's written in plain text and there is another application that needs to process it and return the output. That application is called "XSLT processor". MSXML is actually a pack of different XML processing technologies, among which is XSLT processor. XSLT processors share the same set of standart features, with a few incompatabilities, most of which won't influence you, especially if you use XSLT on the server. The major differences between XSLT processors are speed and the different extensions they support. The less extensions you need to use, the better, but if you do, try to use popular ones and you'll be all right.Scince XML parsers don't differ much, let's think about XSLT processors a bit. I suggest you use the one built in with the S3L of your choice. The reason is that if you need to extend the S3L, you may at some point wish to move to another host, and find yourself in need to reinstall the extension, yet the new host might not allow you that. This means:
  • PHP4 - Salbotron
  • PHP5 - libxslt
  • ASP - MSXML 3
  • ASP.NET 1 - .NET Transform
  • ASP.NET 2 - .NET Compiled Transform
  • Cold Fusion MX 7 - CFX_XSLT

Out of those, I've had most experience with libxslt, and I must say I'm pretty safisfied with it. It has 99% support of XSLT 1.0 and supports a lot of the EXSLT extensions and it doesn't implement any of it's own (or none that I know of).But if you're looking for THE best XSLT processor, I reccomend Saxon. It has complete support for XSLT 1.0 and XSLT 2.0. All optional features, except static typing (I don't yet know what that is) are supported too. Saxon also implements a lot of EXSLT extensions, including a few which libxslt doesn't. It doesn't support few extensions which libxslt does, but scince it's an XSLT 2.0 processor, it provides an equivalent standart way for them or practically eliminates the need for them.In order to install an additional XSLT processor, you'll need to have rights to execute programs from the command line and find XSLT processor with a CLI (Saxon, as well as Xalan and AltovaXML2007 are such processors). Then, find out how you can execute programs in that S3L and call the XSLT processor executable with the proper arguments. For example, in PHP(5?), you can use:

<?php print system("transform.exe file.xml -a"); ?>

where transform.exe is Saxon, file.xml is the XML file (in the same folder as the PHP file and the XSLT processor) that will be processed and the -a argument tells Saxon to follow the processing instruction, rather then use explicit XSLT stylesheet over that XML.As for speed, built-in processors usually run faster then external ones, though that doesn't always need to be true. Saxon and AltovaXML2007 are the two current XSLT 2.0 processors. AltovaXML2007 is free and Schema Awared, while the free version of Saxon is not. At first, you won't need Scema Awareness though, so that shouldn't bother you. AltovaXML2007 is slower then Saxon. Some say it's 100 times slower, but I can't confirm that. As for XSLT 1.0, I haven't made any tests, but again, the built-in thing should be taken into consideration.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...