Revision: 101
Author:   matt
Date:     2006-08-17 14:57:07 +0000 (Thu, 17 Aug 2006)

Log Message:
-----------
Chained transformations added to the docs
Made continuation lines work in config

Modified Paths:
--------------
    trunk/MANIFEST
    trunk/lib/AxKit2/Config.pm
    trunk/lib/AxKit2/Docs/WritingPlugins.pod

Modified: trunk/MANIFEST
===================================================================
--- trunk/MANIFEST      2006-08-16 21:49:31 UTC (rev 100)
+++ trunk/MANIFEST      2006-08-17 14:57:07 UTC (rev 101)
@@ -94,3 +94,4 @@
 plugins/stats
 plugins/uri_to_file
 TODO.txt
+META.yml                                 Module meta-data (added by MakeMaker)

Modified: trunk/lib/AxKit2/Config.pm
===================================================================
--- trunk/lib/AxKit2/Config.pm  2006-08-16 21:49:31 UTC (rev 100)
+++ trunk/lib/AxKit2/Config.pm  2006-08-17 14:57:07 UTC (rev 101)
@@ -140,6 +140,12 @@
         
         chomp;
         
+        if (s/\\$//) {
+            # continuation line...
+            my $line = $_;
+            $_ = $line . $self->_configline;
+        }
+        
         return $_;
     }
 }

Modified: trunk/lib/AxKit2/Docs/WritingPlugins.pod
===================================================================
--- trunk/lib/AxKit2/Docs/WritingPlugins.pod    2006-08-16 21:49:31 UTC (rev 
100)
+++ trunk/lib/AxKit2/Docs/WritingPlugins.pod    2006-08-17 14:57:07 UTC (rev 
101)
@@ -238,11 +238,9 @@
 
   sub hook_xmlresponse {
     my ($self, $input) = @_;
-    
     $self->log(LOGDEBUG, "Serving up a file");
     
     my $stylesheet = $self->get_style;
-    
     my $out = $input->transform(XSLT($stylesheet));
     
     return OK, $out;
@@ -254,8 +252,84 @@
 
 
 
-=head1 Multiple Transformations
+=head1 Chained Transformations
 
+One of the powerful features of AxKit was always being able to easily chain
+transformations together, this makes complex XSLT transformations much simpler,
+among other benefits.
+
+Lets modify our plugin to support multiple XSLT transformations.
+
+The simplest way to do this is to modify our C<XSLT_Style> directive to support
+multiple values, each value being a new XSLT stylesheet. First lets modify our
+configuration to detail what we want:
+
+  XSLT_Style myfirstplugin/stylesheets/sort.xsl \
+             myfirstplugin/stylesheets/default.xsl
+
+The idea here being that one XSLT will sort our dromedaries, and the second 
will
+turn them into HTML.
+
+Lets create our F<sort.xsl> file first:
+
+  <?xml version="1.0" encoding="ISO-8859-1" ?>
+  <xsl:stylesheet 
+    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
+    version="1.0">
+  
+  <xsl:template match="dromedaries">
+  <dromedaries>
+    <xsl:apply-templates select="species">
+        <xsl:sort select="@name"/>
+    </xsl:apply-templates>
+  </dromedaries>
+  </xsl:template>
+  
+  <!-- Identity Template -->
+  <xsl:template match="*|@*">
+    <xsl:copy>
+      <xsl:copy-of select="@*"/>
+      <xsl:apply-templates/>
+    </xsl:copy>
+  </xsl:template>
+  </xsl:stylesheet>
+
+Note the use of the identity template. If you haven't used XSLT before take
+note of that - it's a very useful template for debugging.
+
+So now we need to store a list of XSLT stylesheets in our config, and make use
+of a list in the C<< ->transform() >> method.
+
+The nice thing about C<register_config> is that it automatically copes with
+multi-valued configuration. All we need to do is cope with storing multiple
+values. So we change our C<set_style> sub as follows:
+
+  sub set_style {
+    my ($self, $config, @styles) = @_;
+    my $key = $self->plugin_name . '::style';
+    $config->notes($key, [EMAIL PROTECTED]);
+  }
+
+So rather than taking a single value we take an array and store a reference to
+that array.
+
+We don't need to change C<get_style> as that still returns the right "key" - we
+just need to modify our expectations when we call C<get_style>:
+
+  sub hook_xmlresponse {
+    my ($self, $input) = @_;
+    $self->log(LOGDEBUG, "Serving up a file");
+    
+    my $stylesheets = $self->get_style;
+    my $out = $input->transform(map XSLT($_), @$stylesheets);
+    
+    return OK, $out;
+  }
+
+So instead of running C<XSLT()> once, we map it over C<@$stylesheets>.
+
+And that's it. Restart AxKit and make sure this returns a table of sorted 
results.
+
 =head1 Caching
 
 =head1 What Are the APIs?


Reply via email to