Re: [xsl]Putting PHP Code in XSLT?

Subject: Re: [xsl]Putting PHP Code in XSLT?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 21 Sep 2007 11:44:37 +0100
>        <xsl:processing-instruction name="php">echo "Hello!";   
> ?</xsl:processing-instruction>
> The source code of the section above is there, but it is not working. 

I'm not sure what you mean by not working, It shoudl generate a php
instruction. It will not execute it, you need to put the file on a php
server for that to happen, just as if you generate C code with XSLT,
XSLt will generate it but it won't compile or run it, you have to do
that in a following process.

> When I take the ? off, the product becomes <?php echo "Hello!"; > which 
> is not in HTML format.

You have that backwards. HTML processing instructions just have a ? at
the beginning, although of course you can make the content end with a ?
if you wish. In XML the syntax is a bit different and the processing
instruction is terminated with ?>
<xsl:processing-instruxtion name="zzz">kkkkk</xsl:processing-instruction>

witll generate
<?zzz kkkkk>
if XSLT is generating HTML and
<?zzz kkkkk?>
if it is generating XML.

> The other thing is, why don't we need to do this with Javascript?

If you wanted to put javascript in a processing instruction then you
would need to do that. If you want to put in an element you could do
the same thing, but change xsl:processing-instruction name="php" to
xsl:element name="script" for example. 

XSLT just views php or javascript as text there are no special rules for


The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 

Current Thread