Page 1 of 1
XML and XSLT
Posted: Sun Nov 09, 2003 8:13 am
by sgavan
Hi,
I have a PHP page and in it I would like to "include" an XML file that has a XSL stylesheet. When I use the include() function, without the <? xml-stylesheet?> in the XML file, it loads the XML fine.
But, when I add the <? xml-stylesheet ?> tag I get a parsing error.
Can someone tell me of a way around this and if this approach will work?
I am using this on a Windows platform.
Thanks,
Ste
Posted: Sun Nov 09, 2003 8:32 am
by maniac9
If you're just including it, that won't work, since XML uses <? ?> for the header information. PHP will think the file contains some PHP, which is wrong, and then give you a nice error message. To get around this, you need to print the header and escape the qutoes...like...
Code: Select all
echo("<?xml version="1.0" encoding="ISO-8859-1"?>\n");
Posted: Sun Nov 09, 2003 8:42 am
by volka
or you disable short-tags in your php.ini
http://www.php.net/manual/en/configuration.directives.php wrote:short_open_tag boolean
Tells whether the short form (<? ?>) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use <?xml ?> inline. Otherwise, you can print it with PHP, for example: <?php echo '<?xml version="1.0"'; ?>. Also if disabled, you must use the long form of the PHP open tag (<?php ?>).
Note: This directive also affects the shorthand <?=, which is identical to <? echo. Use of this shortcut requires short_open_tag to be on.
Posted: Sun Nov 09, 2003 10:08 am
by sgavan
Thank you for your replies. I've added the echo() functions to the XML files and the error has disappeared.
But the XML file still does not apply the stylesheet? I have used the same approach as you mentioned for the <?xml-stylesheet?> tag, but no luck!
I am running the PHP server for Windows under XP? Could this have any effect on the outcome? If I open the XML file using IE, then it applies the stylesheet with no problems.
I'm still trying to sort this out, so your help will be much appreciated.
Thank you,
Ste
Posted: Sun Nov 09, 2003 4:59 pm
by volka
php itself does not apply the stylesheet when a xml-file is included.
In fact, php isn't aware it is including a xml-file. It simply searches for php-blocks, anything else is just a stream of characters with no special meaning (to php)
but there are functions to perform a transformation, take a look at
http://php.net/xslt