Re: [xslt] Re: <?php ... ?> and <xsl:output method="html">



>From: Janning Vygen <vygen@gmx.de>
>Reply-To: xslt@gnome.org
>To: xslt@gnome.org
>CC: Christian SG <chr@abelard.de>
>Subject: Re: [xslt] Re: <?php ... ?> and <xsl:output method="html">
>Date: Fri, 5 Dec 2003 15:10:03 +0100
>
>Am Freitag, 5. Dezember 2003 14:22 schrieb csg:
> >
> > To embed PHP code in HTML generated from XML using XSLT (xsltproc),
> > I do this:
> >
> >   - On the XML side I use a XML tag reserved for this task
> >     (for instance, here I use "PHP" for this). In this tag the
> >     markup containing PHP "processing instructions" (which in
> >     reality are no valid PM's) ist quoted through a CDATA
> >     section:
> >
> >       <PHP><![CDATA[<input type="text" name="subject" value="<?php
> > echo $_GET['subject']; ?>"> </input>]]></PHP>
> >
> >   - Inside XSLT I have defined a special template for this PHP tag:
> >
> >       <xsl:template match="PHP">
> >         <xsl:value-of disable-output-escaping="yes" select="." />
> >       </xsl:template>
> >
> > Thats all - the result is valid and working PHP-HTML...
>
>But the source XML doesn't validate anymore against a given DTD
>Because of the <PHP> elements.

Agreed.  The solution we use is something like:

<?xml version="1.0"?>
<page>
        <title><?php 1 < 1 ? 7 & 8 : "'"; ?></title>
</page>

<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="1.0">
        <xsl:output method="html"/>
        <xsl:template match="node() | @*">
                <xsl:copy select=".">
                        <xsl:apply-templates select="node() | @*"/>
                </xsl:copy>
        </xsl:template>
        <xsl:template match="processing-instruction()">
                <xsl:processing-instruction name="php">
                        <xsl:value-of disable-output-escaping="yes" 
select="."/>
                        <xsl:text>?</xsl:text>
                </xsl:processing-instruction>
        </xsl:template>
</xsl:transform>

Obviously, this doesn't allow php in mid-elements, but this is easy enough 
to work around by just outputting the entire opening/closing tags in PHP.

-Brett

_________________________________________________________________
Get holiday tips for festive fun. 
http://special.msn.com/network/happyholidays.armx




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]