1. Dorian Taylor
  2. perl-xml-libxslt


Dorian Taylor  committed eed9098 Draft


  • Participants
  • Parent commits 7cd202a
  • Branches default

Comments (1)

Files changed (5)

File Changes

View file
 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.

File LibXSLT.pm

View file
 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(@_) }
 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>.
 =head1 Parameters
 LibXSLT expects parameters in XPath format. That is, if you wish to pass

File LibXSLT.xs

View file
 char *
+        xsltStylesheetPtr self
+    	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 *
         xsltStylesheetPtr self

File t/05quick.t

View file
 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);
 ok($stylesheet->media_type, ' TODO : Add test name');
+ok($stylesheet->output_method, ' Test existence of output method');
 $out2 = $stylesheet->output_string($results);
 ok($out2, ' TODO : Add test name');

File t/08literal.t

View file
 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);
+is ($stylesheet->output_method, 'xml',
+    'output method is xml BEFORE processing');
+is ($stylesheet->media_type, 'text/xml',
+    'media_type is text/xml BEFORE processing');
 my $results = $stylesheet->transform($source);
 ok ($results, '$results are true.');
-is ($stylesheet->media_type, 'text/html', 'media_type is text/html');
+is ($stylesheet->output_method, 'html',
+    'output method is html AFTER processing');
+is ($stylesheet->media_type, 'text/html',
+    'media_type is text/html AFTER processing');