Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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.


In reply to XML::LibXSLT generates invalid XHTML by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (4)
    As of 2018-06-24 08:18 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?



      Results (126 votes). Check out past polls.

      Notices?