Skip Menu |

This queue is for tickets about the XML-LibXSLT CPAN distribution.

Report information
The Basics
Id: 75778
Status: resolved
Priority: 0/
Queue: XML-LibXSLT

People
Owner: Nobody in particular
Requestors: dorian [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Patch for output method
There's a media_type but no output_method, which is useful for detecting what the output_* methods are going to do with, for instance, empty elements. I more or less just copied and pasted from output_encoding. One thing I noticed is that the default values for both the output method and the media type change if the transform() method is run over what appears to produce an HTML document. I made some changes to t/08literal.t to reflect this, as well as updated the documentation.
Subject: perl-xml-libxslt.diff
diff -r 95fe5c0be0ae LibXSLT.pm --- a/LibXSLT.pm Fri Oct 28 15:49:29 2011 +0100 +++ b/LibXSLT.pm Wed Mar 14 23:25:29 2012 -0700 @@ -511,6 +511,7 @@ sub output_fh { shift->{XML_LIBXSLT_STYLESHEET}->output_fh(@_) } sub output_file { shift->{XML_LIBXSLT_STYLESHEET}->output_file(@_) } sub media_type { shift->{XML_LIBXSLT_STYLESHEET}->media_type(@_) } +sub output_method { shift->{XML_LIBXSLT_STYLESHEET}->output_method(@_) } sub output_encoding { shift->{XML_LIBXSLT_STYLESHEET}->output_encoding(@_) } 1; @@ -834,12 +835,27 @@ Returns the output encoding of the results. Defaults to "UTF-8". +=item output_method() + +Returns the value of the C<method> attribute from C<xsl:output> +(usually C<xml>, C<html> or C<text>). If this attribute is +unspecified, the default value is initially C<xml>. If the +L<transform> method is used to produce an HTML document, as per the +L<XSLT spec|http://www.w3.org/TR/xslt#output>, the default value will +change to C<html>. To override this behavior completely, supply an +C<xsl:output> element in the stylesheet source document. + =item media_type() -Returns the output media_type of the results. Defaults to "text/html". +Returns the value of the C<media-type> attribute from +C<xsl:output>. If this attribute is unspecified, the default media +type is initially C<text/xml>. This default changes to C<text/html> +under the same conditions as L<output_method>. =back +=cut + =head1 Parameters LibXSLT expects parameters in XPath format. That is, if you wish to pass diff -r 95fe5c0be0ae LibXSLT.xs --- a/LibXSLT.xs Fri Oct 28 15:49:29 2011 +0100 +++ b/LibXSLT.xs Wed Mar 14 23:25:29 2012 -0700 @@ -1510,6 +1510,23 @@ RETVAL char * +output_method(self) + xsltStylesheetPtr self + PREINIT: + xmlChar *method; + CODE: + XSLT_GET_IMPORT_PTR(method, self, method) + + RETVAL = (char*) method; + if (RETVAL == NULL) { + /* read http://www.w3.org/TR/xslt#output and tell me how + you'd implement this the way it says to. */ + RETVAL = "xml"; + } + OUTPUT: + RETVAL + +char * output_encoding(self) xsltStylesheetPtr self PREINIT: diff -r 95fe5c0be0ae t/05quick.t --- a/t/05quick.t Fri Oct 28 15:49:29 2011 +0100 +++ b/t/05quick.t Wed Mar 14 23:25:29 2012 -0700 @@ -2,8 +2,8 @@ use strict; use warnings; -# Should be 11. -use Test::More tests => 11; +# Should be 12. +use Test::More tests => 12; use XML::LibXSLT; use XML::LibXML; @@ -41,6 +41,7 @@ my $results = $stylesheet->transform($source); # TEST ok($stylesheet->media_type, ' TODO : Add test name'); +ok($stylesheet->output_method, ' Test existence of output method'); $out2 = $stylesheet->output_string($results); # TEST ok($out2, ' TODO : Add test name'); diff -r 95fe5c0be0ae t/08literal.t --- a/t/08literal.t Fri Oct 28 15:49:29 2011 +0100 +++ b/t/08literal.t Wed Mar 14 23:25:29 2012 -0700 @@ -1,8 +1,8 @@ use strict; use warnings; -# Should be 5. -use Test::More tests => 5; +# Should be 6. +use Test::More tests => 6; use XML::LibXSLT; my $parser = XML::LibXML->new(); @@ -31,9 +31,16 @@ ok ($style, '$style is true.'); my $stylesheet = $xslt->parse_stylesheet($style); +# TEST +#diag($stylesheet->output_method); +is($stylesheet->media_type, 'text/xml', + 'media_type is text/xml BEFORE processing'); + my $results = $stylesheet->transform($source); # TEST ok ($results, '$results are true.'); # TEST -is ($stylesheet->media_type, 'text/html', 'media_type is text/html'); +is ($stylesheet->media_type, 'text/html', + 'media_type is text/html AFTER processing'); +#diag($stylesheet->output_method);
Oops, ignore the last patch. Here's a patch against tip with an addition to Changes.
Subject: perl-xml-libxslt.diff
diff -r 7cd202a4f69b Changes --- a/Changes Sat Feb 25 16:28:27 2012 +0200 +++ b/Changes Wed Mar 14 23:51:26 2012 -0700 @@ -1,5 +1,8 @@ Revision history for Perl extension XML::LibXSLT. + - Add output_method method, update documentation of media_type + (dorian@cpan). + 1.77 Sat Feb 25 16:23:57 IST 2012 - Apply a patch from Michael Ludwig clarifying the quoting of string parameters to the XSLT transformation. diff -r 7cd202a4f69b LibXSLT.pm --- a/LibXSLT.pm Sat Feb 25 16:28:27 2012 +0200 +++ b/LibXSLT.pm Wed Mar 14 23:51:26 2012 -0700 @@ -511,6 +511,7 @@ sub output_fh { shift->{XML_LIBXSLT_STYLESHEET}->output_fh(@_) } sub output_file { shift->{XML_LIBXSLT_STYLESHEET}->output_file(@_) } sub media_type { shift->{XML_LIBXSLT_STYLESHEET}->media_type(@_) } +sub output_method { shift->{XML_LIBXSLT_STYLESHEET}->output_method(@_) } sub output_encoding { shift->{XML_LIBXSLT_STYLESHEET}->output_encoding(@_) } 1; @@ -838,12 +839,27 @@ Returns the output encoding of the results. Defaults to "UTF-8". +=item output_method() + +Returns the value of the C<method> attribute from C<xsl:output> +(usually C<xml>, C<html> or C<text>). If this attribute is +unspecified, the default value is initially C<xml>. If the +L<transform> method is used to produce an HTML document, as per the +L<XSLT spec|http://www.w3.org/TR/xslt#output>, the default value will +change to C<html>. To override this behavior completely, supply an +C<xsl:output> element in the stylesheet source document. + =item media_type() -Returns the output media_type of the results. Defaults to "text/html". +Returns the value of the C<media-type> attribute from +C<xsl:output>. If this attribute is unspecified, the default media +type is initially C<text/xml>. This default changes to C<text/html> +under the same conditions as L<output_method>. =back +=cut + =head1 Parameters LibXSLT expects parameters in XPath format. That is, if you wish to pass diff -r 7cd202a4f69b LibXSLT.xs --- a/LibXSLT.xs Sat Feb 25 16:28:27 2012 +0200 +++ b/LibXSLT.xs Wed Mar 14 23:51:26 2012 -0700 @@ -1513,6 +1513,23 @@ RETVAL char * +output_method(self) + xsltStylesheetPtr self + PREINIT: + xmlChar *method; + CODE: + XSLT_GET_IMPORT_PTR(method, self, method) + + RETVAL = (char*) method; + if (RETVAL == NULL) { + /* read http://www.w3.org/TR/xslt#output and tell me how + you'd implement this the way it says to. */ + RETVAL = "xml"; + } + OUTPUT: + RETVAL + +char * output_encoding(self) xsltStylesheetPtr self PREINIT: diff -r 7cd202a4f69b t/05quick.t --- a/t/05quick.t Sat Feb 25 16:28:27 2012 +0200 +++ b/t/05quick.t Wed Mar 14 23:51:26 2012 -0700 @@ -2,8 +2,8 @@ use strict; use warnings; -# Should be 11. -use Test::More tests => 11; +# Should be 12. +use Test::More tests => 12; use XML::LibXSLT; use XML::LibXML; @@ -41,6 +41,7 @@ my $results = $stylesheet->transform($source); # TEST ok($stylesheet->media_type, ' TODO : Add test name'); +ok($stylesheet->output_method, ' Test existence of output method'); $out2 = $stylesheet->output_string($results); # TEST ok($out2, ' TODO : Add test name'); diff -r 7cd202a4f69b t/08literal.t --- a/t/08literal.t Sat Feb 25 16:28:27 2012 +0200 +++ b/t/08literal.t Wed Mar 14 23:51:26 2012 -0700 @@ -1,8 +1,8 @@ use strict; use warnings; -# Should be 5. -use Test::More tests => 5; +# Should be 8. +use Test::More tests => 8; use XML::LibXSLT; my $parser = XML::LibXML->new(); @@ -31,9 +31,23 @@ ok ($style, '$style is true.'); my $stylesheet = $xslt->parse_stylesheet($style); +# TEST +is ($stylesheet->output_method, 'xml', + 'output method is xml BEFORE processing'); + +# TEST +is ($stylesheet->media_type, 'text/xml', + 'media_type is text/xml BEFORE processing'); + my $results = $stylesheet->transform($source); + # TEST ok ($results, '$results are true.'); # TEST -is ($stylesheet->media_type, 'text/html', 'media_type is text/html'); +is ($stylesheet->output_method, 'html', + 'output method is html AFTER processing'); + +# TEST +is ($stylesheet->media_type, 'text/html', + 'media_type is text/html AFTER processing');
On Thu Mar 15 02:51:50 2012, DORIAN wrote: Show quoted text
> Oops, ignore the last patch. Here's a patch against tip with an addition > to Changes.
Hi, thanks for your patch. I'll look into it soon. Regards, -- Shlomi Fish
The patch was applied in the latest version of XML-LibXSLT . Sorry it took me so long - next time please ping me earlier. Regards, -- Shlomi Fish