XML, XSL, and XHTML - some basic questions
Moderator: General Moderators
XML, XSL, and XHTML - some basic questions
So.... I've been reading this: http://www.tonymarston.net/xml-xsl/reusable-xsl.html and wondering whether I can use it in what I'm doing. The idea sounds great, so I've done a bit of research, and now I understand what XML is, I undertand how to transform it using XSL stylesheets, and to therefore produce XHTML. I also understand that this can be done either on the client-side, or on the server-side.
So... the basics I understand.
The part I'm lacking is the integration with PHP. Let's suppose I have a database which contains data for a forum, like this one. So, I need to basically display various screens which are quite similar - one could be a list of forums, another would be the list of threads within the forum, another could be the list of posts in the thread. These pages are all essentially the same, in that the priciple data is displayed in a tabulated list.
I would usually do this by querying the database, returning a result set and Echoing the results to the page in a foreach loop. The downside to this, is that I end up repeating this kind of code for all "similar" pages, which makes coding the pages a laborious process.
At a basic level, what do I need to do in PHP? Do I need to create an XML document containing data from the database every time the page is opened? Have I misunderstood totally? Once I've got the XML document, I'm fine - I know what to do with it. It's just that area between PHP and the XML document that I don't understand...
If someone would be so kind as to give me a quick overview of what needs to happen, I'd be very grateful.
Thanks,
GM
So... the basics I understand.
The part I'm lacking is the integration with PHP. Let's suppose I have a database which contains data for a forum, like this one. So, I need to basically display various screens which are quite similar - one could be a list of forums, another would be the list of threads within the forum, another could be the list of posts in the thread. These pages are all essentially the same, in that the priciple data is displayed in a tabulated list.
I would usually do this by querying the database, returning a result set and Echoing the results to the page in a foreach loop. The downside to this, is that I end up repeating this kind of code for all "similar" pages, which makes coding the pages a laborious process.
At a basic level, what do I need to do in PHP? Do I need to create an XML document containing data from the database every time the page is opened? Have I misunderstood totally? Once I've got the XML document, I'm fine - I know what to do with it. It's just that area between PHP and the XML document that I don't understand...
If someone would be so kind as to give me a quick overview of what needs to happen, I'd be very grateful.
Thanks,
GM
Re: XML, XSL, and XHTML - some basic questions
It seems that you have to read the other articles at his site tooGM wrote: I would usually do this by querying the database, returning a result set and Echoing the results to the page in a foreach loop. The downside to this, is that I end up repeating this kind of code for all "similar" pages, which makes coding the pages a laborious process.
My main issue with XML/XSL is that it eats lots and lots of cpu/memory and thus not optimal for high-traffic sites.. The other disadvantage was that most webhosts don't have the XSL(T) extension enabled by default...
Re: XML, XSL, and XHTML - some basic questions
Believe me, I'm reading everything I can get my hands on. The only problem is that as I'm learning constantly, I'm constantly rewriting everything, so nothing is ever stable...timvw wrote: It seems that you have to read the other articles at his site too
I'm at a stage at the moment where I can do everything I need to do, but I'm never happy that I'm doing it right
Imho there isn't a good definition for 'doing it right'.
For me it means: meeting the client requirements, with the lowest cost on the long term (Usually clients only care about short term, so this can become difficult. The other disadvantage is that i don't have a crystal ball that says which parts of an application will need to be changed in order to stay synced with changing client requirements...)
These days my approach is the following: Does it meet client requirements? If yes, then stop refactoring/improving the application and deliver.. (If the requirements change later on, i still have the possiblity to refactor to a more intelligent solution)
To make it brief: What do you want to do with the XML/XSL approach? Write down your requirements, and then implement a solution. Adapting the requirements to the limitations of your implementation isn't very workable (and at best a frustrating experience, since nobody likes limitations
)
For me it means: meeting the client requirements, with the lowest cost on the long term (Usually clients only care about short term, so this can become difficult. The other disadvantage is that i don't have a crystal ball that says which parts of an application will need to be changed in order to stay synced with changing client requirements...)
These days my approach is the following: Does it meet client requirements? If yes, then stop refactoring/improving the application and deliver.. (If the requirements change later on, i still have the possiblity to refactor to a more intelligent solution)
To make it brief: What do you want to do with the XML/XSL approach? Write down your requirements, and then implement a solution. Adapting the requirements to the limitations of your implementation isn't very workable (and at best a frustrating experience, since nobody likes limitations
Re: XML, XSL, and XHTML - some basic questions
What is the point of using it then? Just so the data it outputs is really portable? Is that the advandage of XML? I have had a hard time understanding what the point is.timvw wrote:It seems that you have to read the other articles at his site tooGM wrote: I would usually do this by querying the database, returning a result set and Echoing the results to the page in a foreach loop. The downside to this, is that I end up repeating this kind of code for all "similar" pages, which makes coding the pages a laborious process.
My main issue with XML/XSL is that it eats lots and lots of cpu/memory and thus not optimal for high-traffic sites.. The other disadvantage was that most webhosts don't have the XSL(T) extension enabled by default...
Thanks for the answer - to be honest, I'm still not sure that there is an advantage to using XML/XSL over a more intelligent way (than I'm currently using) of displaying data. It's just a new method of doing things that I'd like to play with, to weigh up the pros and cons. The only problem was that I couldn't understand how to go about implementing it in PHP... and to be honest, I still don't. I'll read more...timvw wrote: To make it brief: What do you want to do with the XML/XSL approach? Write down your requirements, and then implement a solution.
Re: XML, XSL, and XHTML - some basic questions
Maintainability, portability, and more.The Ninja Space Goat wrote:What is the point of using it then? Just so the data it outputs is really portable? Is that the advandage of XML? I have had a hard time understanding what the point is.
Here's an example. Lets say google makes a great mapping solution, and you want to be able to include a map from their site on your page - a real estate page. You feed it xml (the address), and it replies with the map (also wrapped in xml).
Then YOUR page in turn is valuable to FakeRealtyCompany, who wants to show your listings to potential buyers. They include your xml in their page, which now includes both your listing, and your map.
Now imagine that you want to check your competitors on a daily basis. Thankfully, they provide an xml feed of THEIR listings, so you can write a script that checks their listings in realtime, and adjust your home cost to match within 10% of theirs - staying competitive on a realtime basis.
But wait, now picture that you want this information on your cellphone. I mean, the selling price of your house is changing every day, so you probably want to know! You can now take that xml from your site, and write an XSLT transform for it so it outputs WML for use on your cell.
Then you end up with a buyer who happens to be blind, so you write a XSLT to produce a nice XHTML compliant version of the page.
I haven't even touched on the ability to change the style, layout, other content on the page (ala my yahoo), and more.
XML is, at its best, a data 'module' that can be manipulated, transferred, shared, and processed easily. The number of things that enables is incredibly large.
Re: XML, XSL, and XHTML - some basic questions
WOW... that really clears things up. Thank you!Roja wrote:Maintainability, portability, and more.The Ninja Space Goat wrote:What is the point of using it then? Just so the data it outputs is really portable? Is that the advandage of XML? I have had a hard time understanding what the point is.
Here's an example. Lets say google makes a great mapping solution, and you want to be able to include a map from their site on your page - a real estate page. You feed it xml (the address), and it replies with the map (also wrapped in xml).
Then YOUR page in turn is valuable to FakeRealtyCompany, who wants to show your listings to potential buyers. They include your xml in their page, which now includes both your listing, and your map.
Now imagine that you want to check your competitors on a daily basis. Thankfully, they provide an xml feed of THEIR listings, so you can write a script that checks their listings in realtime, and adjust your home cost to match within 10% of theirs - staying competitive on a realtime basis.
But wait, now picture that you want this information on your cellphone. I mean, the selling price of your house is changing every day, so you probably want to know! You can now take that xml from your site, and write an XSLT transform for it so it outputs WML for use on your cell.
Then you end up with a buyer who happens to be blind, so you write a XSLT to produce a nice XHTML compliant version of the page.
I haven't even touched on the ability to change the style, layout, other content on the page (ala my yahoo), and more.
XML is, at its best, a data 'module' that can be manipulated, transferred, shared, and processed easily. The number of things that enables is incredibly large.
I actually have a project coming up where this could help me immensely.
Re: XML, XSL, and XHTML - some basic questions
Egads, I thought I rambled on endlessly and was entirely unclear. Glad to see it had some value.The Ninja Space Goat wrote:WOW... that really clears things up. Thank you!
I actually have a project coming up where this could help me immensely.