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);