7 |
# $Id$ |
# $Id$ |
8 |
# |
# |
9 |
# $Log$ |
# $Log$ |
10 |
|
# Revision 1.2 2003/05/01 17:03:52 joko |
11 |
|
# revamped processing: a) _calculate and b) _apply (NEW) |
12 |
|
# |
13 |
# Revision 1.1 2003/04/30 02:36:32 joko |
# Revision 1.1 2003/04/30 02:36:32 joko |
14 |
# initial commit |
# initial commit |
15 |
# |
# |
51 |
my $self = bless {}, $class; |
my $self = bless {}, $class; |
52 |
my $args = $self->__parse_args(@_); |
my $args = $self->__parse_args(@_); |
53 |
|
|
54 |
$self->__init_default_macros(); |
$self->{DEBUG} = $args->{debug}; |
55 |
|
$self->{WARNINGS} = $args->{warnings}; |
56 |
|
|
57 |
#=pod |
$self->__init_default_macros(); |
|
$self->{XSLT_ENGINE} = XML::XSLT->new( |
|
|
Source => $self->get_macro("xupdate2xsl"), |
|
|
debug => $args->{debug}, |
|
|
warnings => $args->{warnings} |
|
|
); |
|
|
#=cut |
|
58 |
|
|
|
#print Dumper($self); |
|
59 |
return $self; |
return $self; |
60 |
|
|
61 |
} |
} |
62 |
|
|
63 |
sub get_macro { |
sub get_stylesheet { |
64 |
my $self = shift; |
my $self = shift; |
65 |
my $name = shift; |
my $name = shift; |
66 |
return $self->{MACROS}->{$name}; |
return $self->{XML}->{xsl}->{$name}; |
67 |
|
} |
68 |
|
|
69 |
|
sub set_stylesheet { |
70 |
|
my $self = shift; |
71 |
|
my $name = shift; |
72 |
|
my $xml = shift; |
73 |
|
my $options = shift; |
74 |
|
if ($options->{encap}) { |
75 |
|
$xml = qq(<?xml version="1.0" encoding="ISO-8859-1"?> |
76 |
|
|
77 |
|
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
78 |
|
|
79 |
|
<!-- |
80 |
|
This XML Stylesheet is the result of a translation from |
81 |
|
XUpdate lingo. It actually applies the payload to the |
82 |
|
original xml document. (it's the second processing step!) |
83 |
|
--> |
84 |
|
|
85 |
|
<xsl:output method="xml" /> |
86 |
|
|
87 |
|
$xml |
88 |
|
|
89 |
|
</xsl:stylesheet> |
90 |
|
); |
91 |
|
} |
92 |
|
$self->{XML}->{xsl}->{$name} = $xml; |
93 |
} |
} |
94 |
|
|
95 |
sub open_document { |
sub open_document { |
108 |
|
|
109 |
sub process { |
sub process { |
110 |
my $self = shift; |
my $self = shift; |
111 |
# first, translate xupdate to xsl |
$self->_calculate(); |
112 |
$self->{XSLT_ENGINE}->open_xml( $self->{XML}->{xupdate} ); |
$self->_apply(); |
|
$self->{XSLT_ENGINE}->process(); |
|
|
$self->{XML}->{XSL} = $self->{XSLT_ENGINE}->toString(); |
|
113 |
} |
} |
114 |
|
|
115 |
|
# First, translate the xupdate payload to xsl. |
116 |
|
# FIXME: do DOM only! |
117 |
|
sub _calculate { |
118 |
|
my $self = shift; |
119 |
|
$self->{XSLT_ENGINE_PREP} = XML::XSLT->new( |
120 |
|
Source => $self->get_stylesheet("xupdate2xsl"), |
121 |
|
debug => $self->{DEBUG}, |
122 |
|
warnings => $self->{WARNINGS} |
123 |
|
); |
124 |
|
$self->{XSLT_ENGINE_PREP}->open_xml( $self->{XML}->{xupdate} ); |
125 |
|
$self->{XSLT_ENGINE_PREP}->process(); |
126 |
|
$self->set_stylesheet( "_worker", $self->{XSLT_ENGINE_PREP}->toString(), { encap => 1 } ); |
127 |
|
} |
128 |
|
|
129 |
|
# After that, use this worker xsl to actually apply the changes to the original document. |
130 |
|
# FIXME: do DOM only! |
131 |
|
sub _apply { |
132 |
|
my $self = shift; |
133 |
|
#print $self->get_stylesheet("_worker"), "\n"; |
134 |
|
#return; |
135 |
|
$self->{XSLT_ENGINE_LIVE} = XML::XSLT->new( |
136 |
|
Source => $self->get_stylesheet("_worker"), |
137 |
|
debug => $self->{DEBUG}, |
138 |
|
warnings => $self->{WARNINGS} |
139 |
|
); |
140 |
|
$self->{XSLT_ENGINE_LIVE}->open_xml( $self->{XML}->{document} ); |
141 |
|
$self->{XSLT_ENGINE_LIVE}->process(); |
142 |
|
$self->{XML}->{result} = $self->{XSLT_ENGINE_LIVE}->toString(); |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
sub toString { |
sub toString { |
147 |
my $self = shift; |
my $self = shift; |
148 |
return $self->{XML}->{XSL}; |
return $self->{XML}->{result}; |
149 |
} |
} |
150 |
|
|
151 |
|
|
152 |
###################################################################### |
###################################################################### |
153 |
# AUXILIARY METHODS |
# AUXILIARY METHODS |
154 |
|
|
155 |
# Argument parsing with backwards compatibility. |
# Argument parsing (with backwards compatibility hook). |
156 |
sub __parse_args { |
sub __parse_args { |
157 |
my $self = shift; |
my $self = shift; |
158 |
my %args; |
my %args; |
170 |
|
|
171 |
sub __init_default_macros { |
sub __init_default_macros { |
172 |
my $self = shift; |
my $self = shift; |
173 |
$self->{MACROS}->{xupdate2xsl} = qq(<?xml version="1.0" encoding="ISO-8859-1"?> |
$self->{XML}->{xsl}->{xupdate2xsl} = qq(<?xml version="1.0" encoding="ISO-8859-1"?> |
174 |
|
|
175 |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
176 |
|
|
177 |
<!-- |
<!-- |
178 |
Purpose of this XML Stylesheet is to implement a set of templates |
Purpose of this XML Stylesheet is to implement a set of templates |
179 |
to translate XUpdate lingo into an intermediate xslt stylesheet |
to translate XUpdate lingo into an intermediate xslt stylesheet |
180 |
which actually performs the update to the original xml document. |
which actually performs the update to the original xml document |
181 |
|
in a second step. |
182 |
--> |
--> |
183 |
|
|
184 |
<xsl:output method="xml" /> |
<xsl:output method="xml" /> |