Generating xml with php to use xslt client side

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jack Williard
Forum Newbie
Posts: 1
Joined: Tue Sep 06, 2005 8:37 am

Generating xml with php to use xslt client side

Post by Jack Williard »

I am trying to generate xml that will be processed client side with an associated xslt template. My php generates well-formed xml and if I manually copy and paste the ouput to an .xml file, it generates xhtml properly. However, when the php is accessed directly, I get this error:
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Invalid at the top level of the document. Error processing resource 'file:///C:/Documents and Settings/jwilliard/My Documen...

<?xml-stylesheet type='text/xsl' href='./as.xslt'?>";
---------------------------------------------------^
Researching the problem, I noticed this at w3schools.com:
Generating XML with ASP
XML can be generated on a server without any installed XML software.

To generate an XML response from the server - simply write the following code and save it as an ASP file on the web server:

<%
response.ContentType="text/xml"
response.Write("<?xml version='1.0' encoding='ISO-8859-1'?>")
response.Write("<note>")
response.Write("<from>Jani</from>")
response.Write("<to>Tove</to>")
response.Write("<message>Remember me this weekend</message>")
response.Write("</note>")
%>

Note that the content type of the response must be set to "text/xml".

How do I set the content type in php? Is this my problem?

Thank you huge for any help.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the header() function is used to set the content-type of the page.

(remember to place the call before any output is sent to the browser (via php or not)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

If you accessing the file through your filesystem..(resource 'file:///C:/Documents and Settings/jwilliard/My Documen... ) the script will not be parsed..

If you have static XML and XSL files, it's possible to have an XSLT process.. Just search this forum on XML XSL as we've talked about this last weekend or so.
Post Reply