Subject: Re: [xsl] XML > XSL > PHP possible? From: "Toshihiko Makita tmakita@xxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 30 Sep 2022 01:43:32 -0000 |
I'm using following template with xsl:output/@method="html".
It's works fine now in user projects.
B B B <!--
B B B function:B B Processing instruction output template
B B B param:B B B B B prmPiName, prmPiContent
B B B return:B B B B text()+
B B B note:B B B B B B Saxon does not outputs processing instruction as expected in HTML5 output.
B B B B B B B B B B B B B B B <?php o= ?> is converted into <?php o= >
B B B B B B B B B B B B B B B To avoid this error, use xsl:text instead.
B B B -->
B B B <xsl:template name="outputPI" as="text()+">
B B B B B B B <xsl:param name="prmPiName" as="xs:string"/>
B B B B B B B <xsl:param name="prmPiContent" as="xs:string"/>
B B B B B B B <xsl:text disable-output-escaping="yes"><?</xsl:text>
B B B B B B B <xsl:value-of select="$prmPiName"/>
B B B B B B B <xsl:text> </xsl:text>
B B B B B B B <xsl:value-of select="$prmPiContent" disable-output-escaping="yes"/>
B B B B B B B <xsl:text></xsl:text>
B B B B B B B <xsl:text disable-output-escaping="yes">?></xsl:text>
B B B </xsl:template>
On 9/30/2022 9:50 AM, Michael B Allen ioplex@xxxxxxxxx wrote:Hi,
I'm trying to generate PHP from XML. This seems like something that should be possible but I fear it is not.
Consider the following test.xml > test.xsl > test.php example:
<?xml version="1.0"?>XSL <<<<<<<<<
<xsl:stylesheet version="1.0" B B B B xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" B B B B encoding="UTF-8" B B B B indent="no"/> <!-- <xsl:output method="xml" B B B B omit-xml-declaration="yes" B B B B encoding="UTF-8"/> -->
<xsl:template match="@*|node()"> B B B B <xsl:copy> B B B B B B B B <xsl:apply-templates select="@*|node()"/> B B B B </xsl:copy> </xsl:template>
<xsl:template match="processing-instruction('php')"> B B B B <xsl:processing-instruction name="php"> B B B B B B B B <xsl:value-of disable-output-escaping="yes" select="."/> B B B B </xsl:processing-instruction> </xsl:template>
<xsl:template match="html"> B B B B <xsl:text disable-output-escaping="yes"><!DOCTYPE html> </xsl:text> B B B B <html lang="en"> B B B B B B B B <xsl:apply-templates/> B B B B </html> </xsl:template>
</xsl:stylesheet>
XML <<<<<<<<<<html> <head> <title>test</title> </head> <body>
<header></header>
<main>
<?php echo '<b>Hello, World!</b>'; ?> <img src="test.png" alt="test"/>
</main>
<footer> </footer>
</body> </html>
With output method="html":OUTPUT METHOD HTML <<<<<<<<<
$ xsltproc -o test.php test.xsl test.xml
$ cat test.php
<!DOCTYPE html>
<html lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>test</title>
</head>
<body>
<header></header>
<main>
<?php echo '<b>Hello, World!</b>'; <img src="test.png" alt="test">
</main>
<footer> </footer>
</body> </html>
the trailing '?' is not present which causes PHP to generate an error:
PHP Parse error:B syntax error, unexpected '>', expecting end of file in /path/to/test.php on line N
With output method="xml":OUTPUT METHOD XML <<<<<<<<<
$ xsltproc -o test.php test.xsl test.xml $ cat test.php <!DOCTYPE html> <html lang="en"> <head> <title>test</title> </head> <body>
<header/>
<main>
<?php echo '<b>Hello, World!</b>'; ?> <img src="test.png" alt="test"/>
</main>
<footer> </footer>
</body> </html>
the trailing ? is present but the result is not valid HTML because of the self closing tags in void elements like img, header, img, input, ...
Is there some trick to work-around this?
Mike
-- /*-------------------------------------------------- Toshihiko Makita Development Group. Antenna House, Inc. Ina Branch E-Mail tmakita@xxxxxxxxxxxxx 8077-1 Horikita Minamiminowa Vil. Kamiina Co. Nagano Pref. 399-4511 Japan Tel +81-265-76-9300 Fax +81-265-78-1668 Web site: http://www.antenna.co.jp/ http://www.antennahouse.com/ --------------------------------------------------*/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XML > XSL > PHP possible?, Toshihiko Makita tma | Thread | Re: [xsl] XML > XSL > PHP possible?, Michael B Allen iopl |
Re: [xsl] XML > XSL > PHP possible?, Toshihiko Makita tma | Date | Re: [xsl] XML > XSL > PHP possible?, Michael B Allen iopl |
Month |