--- nfo/perl/libs/XML/XUpdate/XSLT.pm 2003/04/30 02:36:32 1.1
+++ nfo/perl/libs/XML/XUpdate/XSLT.pm 2003/05/01 17:03:52 1.2
@@ -4,9 +4,12 @@
#
# By Andreas Motl, andreas.motl@ilo.de
#
-# $Id: XSLT.pm,v 1.1 2003/04/30 02:36:32 joko Exp $
+# $Id: XSLT.pm,v 1.2 2003/05/01 17:03:52 joko Exp $
#
# $Log: XSLT.pm,v $
+# Revision 1.2 2003/05/01 17:03:52 joko
+# revamped processing: a) _calculate and b) _apply (NEW)
+#
# Revision 1.1 2003/04/30 02:36:32 joko
# initial commit
#
@@ -48,25 +51,45 @@
my $self = bless {}, $class;
my $args = $self->__parse_args(@_);
- $self->__init_default_macros();
+ $self->{DEBUG} = $args->{debug};
+ $self->{WARNINGS} = $args->{warnings};
-#=pod
- $self->{XSLT_ENGINE} = XML::XSLT->new(
- Source => $self->get_macro("xupdate2xsl"),
- debug => $args->{debug},
- warnings => $args->{warnings}
- );
-#=cut
+ $self->__init_default_macros();
- #print Dumper($self);
return $self;
}
-sub get_macro {
+sub get_stylesheet {
my $self = shift;
my $name = shift;
- return $self->{MACROS}->{$name};
+ return $self->{XML}->{xsl}->{$name};
+}
+
+sub set_stylesheet {
+ my $self = shift;
+ my $name = shift;
+ my $xml = shift;
+ my $options = shift;
+ if ($options->{encap}) {
+ $xml = qq(
+
+
+
+
+
+
+
+$xml
+
+
+ );
+ }
+ $self->{XML}->{xsl}->{$name} = $xml;
}
sub open_document {
@@ -85,22 +108,51 @@
sub process {
my $self = shift;
- # first, translate xupdate to xsl
- $self->{XSLT_ENGINE}->open_xml( $self->{XML}->{xupdate} );
- $self->{XSLT_ENGINE}->process();
- $self->{XML}->{XSL} = $self->{XSLT_ENGINE}->toString();
+ $self->_calculate();
+ $self->_apply();
}
+# First, translate the xupdate payload to xsl.
+# FIXME: do DOM only!
+sub _calculate {
+ my $self = shift;
+ $self->{XSLT_ENGINE_PREP} = XML::XSLT->new(
+ Source => $self->get_stylesheet("xupdate2xsl"),
+ debug => $self->{DEBUG},
+ warnings => $self->{WARNINGS}
+ );
+ $self->{XSLT_ENGINE_PREP}->open_xml( $self->{XML}->{xupdate} );
+ $self->{XSLT_ENGINE_PREP}->process();
+ $self->set_stylesheet( "_worker", $self->{XSLT_ENGINE_PREP}->toString(), { encap => 1 } );
+}
+
+# After that, use this worker xsl to actually apply the changes to the original document.
+# FIXME: do DOM only!
+sub _apply {
+ my $self = shift;
+ #print $self->get_stylesheet("_worker"), "\n";
+ #return;
+ $self->{XSLT_ENGINE_LIVE} = XML::XSLT->new(
+ Source => $self->get_stylesheet("_worker"),
+ debug => $self->{DEBUG},
+ warnings => $self->{WARNINGS}
+ );
+ $self->{XSLT_ENGINE_LIVE}->open_xml( $self->{XML}->{document} );
+ $self->{XSLT_ENGINE_LIVE}->process();
+ $self->{XML}->{result} = $self->{XSLT_ENGINE_LIVE}->toString();
+}
+
+
sub toString {
my $self = shift;
- return $self->{XML}->{XSL};
+ return $self->{XML}->{result};
}
######################################################################
# AUXILIARY METHODS
-# Argument parsing with backwards compatibility.
+# Argument parsing (with backwards compatibility hook).
sub __parse_args {
my $self = shift;
my %args;
@@ -118,14 +170,15 @@
sub __init_default_macros {
my $self = shift;
- $self->{MACROS}->{xupdate2xsl} = qq(
+ $self->{XML}->{xsl}->{xupdate2xsl} = qq(