Simon Cozens <[EMAIL PROTECTED]> writes:
> [...]
> The uploaded file
>
> Template-Plugin-XSLT-1.0.tar.gz
>
> has entered CPAN as
>
> file: $CPAN/authors/id/S/SI/SIMON/Template-Plugin-XSLT-1.0.tar.gz
> size: 2509 bytes
This week I've got around to play with this small but fine plugin.
Some ideas came into my mind:
1) Wouldn't it be great if I could use a TT template/block as a XSL
stylesheet? This would allow to keep everything in one place, and
enable TT variables in the stylesheet, and....
However, it is likely that this can't be done: XSLT allows
e.g. <xsl:include href="foo.xsl"/>, and I don't see any chance to
define what should be a relative URL to a TT block or template.
2) Wouldn't it be great if I could pass parameters to the filter?
I've attached a diff which works for me. Any opinions?
3) What is the proper behaviour of a filter when it fails to operate?
The XSLT plugin just returns, which gives an empty string in the
output, if I want it to filter invalid XML. Couldn't we let it
die() in that case and leave it to the caller to [% CATCH %] such
errors?
--
Cheers,
haj
--- /usr/lib/perl5/site_perl/5.8.2/Template/Plugin/XSLT.pm 2004-03-21 11:15:09.000000000 +0100
+++ Oook/Template/Plugin/XSLT.pm 2004-04-20 13:56:38.622370100 +0200
@@ -28,9 +28,11 @@
return $self->error("Stylesheet parsing errored") unless $self->{stylesheet};
+ $self->{ _DYNAMIC } = 1;
+
return $self;
}
sub filter {
- my ($self, $text) = @_;
+ my ($self, $text, $options, $params) = @_;
my $xml;
eval {
@@ -40,6 +42,12 @@
return $self->error("XML parsing errored") unless $xml;
+ my %params;
+ if (scalar(grep {/^literal$/} @$options)) {
+ %params = %$params;
+ } else {
+ %params = XML::LibXSLT::xpath_to_string(%$params);
+ }
return $self->{ stylesheet}->output_string(
- $self->{ stylesheet }->transform( $xml )
+ $self->{ stylesheet }->transform( $xml,%params )
);
}
@@ -61,4 +69,8 @@
[% foo.as_xml | $transform %]
+ [% foo.as_xml | $transform stringparam = 'param' %]
+
+ [% foo.as_xml | $transform 'literal' stringparam = "'param'" %]
+
=head1 DESCRIPTION
@@ -67,4 +79,9 @@
the XML does not parse, an exception will be raised.
+Stylesheet parameters may be passed to the filter as 'key=value' pairs.
+Usually they are escaped as string parameters since this is by far the most
+common use of stylesheet parameters. To define parameters literally, add a
+positional parameter 'literal' before the key=value pairs.
+
=head1 AUTHOR