xsl-list
[Top] [All Lists]

Re: XSLT w/ PHP, ASP, JSP Processing Instructions

2005-12-05 16:02:04
Michael B Allen wrote:

But I'm a little worried because Saxon complains that the two templates
are ambiguous. I guess node() also selects PIs? Is there a way to excplide
'php' PIs from The Identity Transform?

Just add priority="10" to the template that process PHP PI.

But the missing '?' causes the script (PHP at least) to fail. If we
use the xml output method to subvert the no trailing '?' requirement,
all PIs still must not contain '>' or '<'. Even if it were practical
to use entity references for these characters (which it's not), PHP
will generate a parse error on them. Also XHTML does not have <?xml
version="1.0"?> at the top AFAIK.

Can someone recommend a robust, compliant method for transforming XML
to HTML or XHTML with PHP compatible processing instructions? Surely
the XSLT founding fathers must have considered this use-case.

The problem here is that XSLT was designed to output XML, HTML or plain text. Scripting languages like PHP or ASP were not designed in a way that is compatible neither with HTML, nor with XML. Output of PHP/ASP can be of course well-formed, but source of script doesn't guarantee this. For example in PHP you can have:

<input name="age" value="<?php echo $age?>">

It is not legal to have '<' character inside attribute value in XML/HTML.

This and many other reasons cause that PHP/ASP doesn't play very well with XML if you want to treat *source* of script as an XML document (PHP is still much better in this then ASP with <%).

When fathers of XSLT designed XSLT (during 1997-99), there was PHP/FI (2.0) in use AFAIK, and this version of language used SGML friendly <?...> separators. <?...?> notation was added in PHP3, but anyway PHP was not so popular at that time as it is in recent years.

I think that best what you can do is to output PHP/ASP markup with d-o-e. Something like:

<xsl:text disable-output-escaping="yes">&lt;?php </xsl:text>
<xsl:text disable-output-escaping="yes">...PHP code goes here...</xsl:text>
<xsl:text disable-output-escaping="yes">?></xsl:text>

You can define internal text entites for the first and the last xsl:text to save typing in XSLT code.

Some web scripting languages (e.g. JSP since 1.2) started to offer alternative XML-based syntax in recent years. But there is no such thing for PHP or ASP AFAIK.

                                Jirka

--
------------------------------------------------------------------
  Jirka Kosek     e-mail: jirka(_at_)kosek(_dot_)cz     http://www.kosek.cz
------------------------------------------------------------------
  Profesionální školení a poradenství v oblasti technologií XML.
     Podívejte se na náš nově spuštěný web http://DocBook.cz
       Podrobný přehled školení http://xmlguru.cz/skoleni/
------------------------------------------------------------------
                   Nejbližší termíny školení:
     ** XSLT 13.-16.3.2006 ** XML schémata 24.-26.4.2006 **
       ** DocBook 15.-17.5.2006 ** XSL-FO 12.-13.6.2006 **
------------------------------------------------------------------

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature