Commits

Anonymous committed eed9098

wat

  • Participants
  • Parent commits 7cd202a

Comments (0)

Files changed (5)

 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.
 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;
 
 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
         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:
 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;
 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');
 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();
 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');