Create a doc with <?php .?> before DOCTYPE declaration
Added by Anonymous over 15 years ago
Legacy ID: #6744660 Legacy Poster: Claes (claeshelgeson)
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
Replies (4)
Please register to reply
RE: Create a doc with <?php .?> before DOCTYPE declaration - Added by Anonymous over 15 years ago
Legacy ID: #6745497 Legacy Poster: Michael Kay (mhkay)
I don't think there's any way to get the serializer to output anything before it outputs the DOCTYPE declaration. One solution would be to send the transformation output to an OutputStream to which you have already written the <?php?> stuff (from the calling application, or from the OutputURIResolver). Another solution would be to generate both the PHP header and the DOCTYPE declaration as text from your stylesheet, using disable-output-escaping or character maps, rather than having the DOCTYPE declaration generated by the serializer in response to your xsl:output properties. Or perhaps you don't really need the DOCTYPE declaration at all? In that case you might be able to generate the PHP header using xsl:processing-instruction.
RE: Create a doc with <?php .?> before DOCTYPE declaration - Added by Anonymous over 15 years ago
Legacy ID: #6746617 Legacy Poster: Claes (claeshelgeson)
Thanks Michael, I'll give the 2nd or 3rd alternative a try and see if I can manage... /Claes
RE: Create a doc with <?php .?> before DOCTYPE declaration - Added by Anonymous over 15 years ago
Legacy ID: #6748122 Legacy Poster: Claes (claeshelgeson)
I just started with trying to remove the <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> which is output in every php file before <html> tag. With the enthusiasm of a beginner I removed the doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" from the <xsl:output method="html" indent="yes" omit-xml-declaration="yes" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" encoding="utf-8"/> but still the <!DOCTYPE... shows up in each file. 1. What part of the transformation is adding the <!DOCTYPE...? and is there an easy way to remove it? 2. If I succeed to remove the <!DOCTYPE... and add the <?php include ?> statement, it is vital that this statement is the very FIRST line of code in the file. Not even a space, since that is output to the browser. [The php code might redirect the user with "header('Location:...') which cannot be done if something is already output]. Any idea of how to accomplish that? Did I mention I'm using Instant SAXON, i.e. only the saxon.exe file locally installed. All comments appreciated! /Claes
RE: Create a doc with <?php .?> before DOCTYPE declaration - Added by Anonymous over 15 years ago
Legacy ID: #6748488 Legacy Poster: Michael Kay (mhkay)
>Did I mention I'm using Instant SAXON, i.e. only the saxon.exe file locally installed. That's amazing. It means you are also using the Microsoft Java VM - I had no idea it was still possible to get that running on any modern version of Windows. This Saxon release dates from 2003, so answering technical questions about it would require considerable archaeology. I also see you specify xsl:stylesheet version="1.1" and use instructions from the aborted 1.1 specification, such as xsl:document. Again, it will require a lot of historical research to work out how this was supposed to behave. I suggest you make the effort to move forward to XSLT 2.0 and a more recent Saxon release. Michael Kay http://www.saxonica.com/
Please register to reply