Welcome to WebmasterWorld Guest from 184.73.126.70

Forum Moderators: httpwebwitch

Message Too Old, No Replies

Create a doc with <?php .?> before DOCTYPE declaration

   
11:10 pm on Mar 10, 2009 (gmt 0)

5+ Year Member



Hi,
I've been using Saxon for creating a website's html and php files from our XML source files.
In our next project I need to be able to output some php code at the very top of each document, before the doctype declaration and <html> tag.
The big Q is... how do I do that?

This is what I use today:


<xsl:transform version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" encoding="UTF-8"/>
:
:
<xsl:template mode="newpage" match="*">
<xsl:param name="filename">
:
</xsl:param>
<xsl:document href="{normalize-space($filename)}">
<html>
<xsl:apply-templates select="." mode="skel.header">
:
:

but I cannot figure out how to include some php code at the very top.

My generated php files come out as:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
:
:

but I would like:

<?php include 'authorizeUser.php' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
:
:

Is that possible...?
Thanks!
/Claes

[edited by: eelixduppy at 11:20 pm (utc) on Mar. 11, 2009]
[edit reason] disabled smileys [/edit]

3:56 pm on Mar 11, 2009 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



you're using Saxon to generate PHP? That's rather unorthodox... but if you can make it work, could be quite a powerful technique! Just curious, is this being done in preprocessing, or at runtime?

remove the <xsl:output> element, or change its method attribute. When you start injecting <?stuff?>, You're not outputting HTML any more :)

try putting this in your XSLT

<xsl:text>
<![CDATA[
<?php print("test"); ?>
]]>
</xsl:text>

when you do output the php, you'll need to ensure that the output is being parsed by the PHP engine. depending on when/how the XML->XSLT->output is being done, you might just end up with PHP code rendered on the page. Do please report back here if you get it working!

8:19 am on Mar 12, 2009 (gmt 0)

5+ Year Member



Thanks httpwebwitch,
I'll try to get it working tonight/tomorrow.
We are preprocessing the php files and then uploading to server.
/Claes