http://www.perlmonks.org?node_id=475895

Ovid has asked for the wisdom of the Perl Monks concerning the following question:

In trying to test some XSLT code I've been working on, I'm trying to produce valid XHTML and use Test::XML to verify the results. Unfortunately, XML::LibXSLT appears to be generating an unclosed meta tag for the HTML content type. Even if I include my own meta tag, it's removing mine and substituting the invalid one.

As a workaround, I've stripped the meta tag from the resulting HTML and used is_xml() in my test, but I'd much rather have my code produce a valid meta tag. A minimal test case is below with my output in the __DATA__ section. Does anyone get valid XHTML results? If so, I'm running this on OS X. xslt-config returns 1.1.11.

#!/usr/bin/perl use strict; use warnings; use XML::LibXML; use XML::LibXSLT; my $parser = XML::LibXML->new; my $doc = $parser->parse_string(_xml()); my $style_doc = $parser->parse_string(_stylesheet()); my $xslt = XML::LibXSLT->new; my $sheet = $xslt->parse_stylesheet($style_doc); my $html = $sheet->transform($doc); print $sheet->output_string($html); sub _xml { return <<' END_XML'; <?xml version="1.0"?> <resources> <description>Available instances</description> <resource id="foo"/> <resource id="bar"/> <resource id="bar"/> </resources> END_XML } sub _stylesheet { return <<' END_STYLE_SHEET'; <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:template match="/"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UT +F-8"/> <title><xsl:value-of select="/resources/description" /></title +> </head> <body> <table> <xsl:for-each select="resources"> <xsl:apply-templates select="./resource" /> </xsl:for-each> </table> </body> </html> </xsl:template> <xsl:template match="resource"> <tr> <td> <xsl:value-of select="@id" /> </td> </tr> </xsl:template> </xsl:stylesheet> END_STYLE_SHEET } __DATA__ <html xmlns:fo="http://www.w3.org/1999/XSL/Format"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Available instances</title> </head> <body><table> <tr><td>foo</td></tr> <tr><td>bar</td></tr> <tr><td>bar</td></tr> </table></body> </html>

Cheers,
Ovid

New address of my CGI Course.