Subject: Re: [xsl] XML > XSL > PHP possible? From: "Toshihiko Makita tmakita@xxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 30 Sep 2022 01:22:04 -0000 |
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" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" indent="no"/> <!-- <xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8"/> -->
<xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
<xsl:template match="processing-instruction('php')"> <xsl:processing-instruction name="php"> <xsl:value-of disable-output-escaping="yes" select="."/> </xsl:processing-instruction> </xsl:template>
<xsl:template match="html"> <xsl:text disable-output-escaping="yes"><!DOCTYPE html> </xsl:text> <html lang="en"> <xsl:apply-templates/> </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: 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 -> |
---|---|---|
[xsl] XML > XSL > PHP possible?, Michael B Allen iopl | Thread | Re: [xsl] XML > XSL > PHP possible?, Toshihiko Makita tma |
[xsl] XML > XSL > PHP possible?, Michael B Allen iopl | Date | Re: [xsl] XML > XSL > PHP possible?, Toshihiko Makita tma |
Month |