/[cvs]/nfo/perl/libs/XML/XUpdate/XSLT.pm
ViewVC logotype

Diff of /nfo/perl/libs/XML/XUpdate/XSLT.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by joko, Thu May 1 20:11:49 2003 UTC revision 1.7 by joko, Tue May 13 09:32:22 2003 UTC
# Line 7  Line 7 
7  #    $Id$  #    $Id$
8  #  #
9  #    $Log$  #    $Log$
10    #    Revision 1.7  2003/05/13 09:32:22  joko
11    #    minor update to pod
12    #
13    #    Revision 1.6  2003/05/07 03:11:28  joko
14    #    updated pod: new section "References", added item to "Todo" section
15    #
16    #    Revision 1.5  2003/05/06 14:24:06  joko
17    #    doesn't use Carp any more
18    #    updated pod
19    #    attempt to rewrite xml to make it more human readable using helper modules from CPAN (node indentation, etc.)
20    #
21    #    Revision 1.4  2003/05/01 23:40:32  joko
22    #    minor update: commented debugging part
23    #
24  #    Revision 1.3  2003/05/01 20:11:49  joko  #    Revision 1.3  2003/05/01 20:11:49  joko
25  #    * added pod from xupdate.pl  #    * added pod from xupdate.pl
26  #    - extracted xml to external files  #    - extracted xml to external files
# Line 22  Line 36 
36    
37  =head1 NAME  =head1 NAME
38    
39  XML::XUpdate::XSLT - A perl module for updating xml documents using XUpdate via XSLT.    XML::XUpdate::XSLT - A perl module for updating xml documents using XUpdate via XSLT.
40    
41    
42  =head3 Overview  =head3 Overview
# Line 34  XML::XUpdate::XSLT - A perl module for u Line 48  XML::XUpdate::XSLT - A perl module for u
48    xupdate - Process XUpdate commands against an XML document.    xupdate - Process XUpdate commands against an XML document.
49    
50    
51  =head3 Their implementations differ:  =head4 Their implementations differ:
52    
53      1. xupdate (by Petr Pajas) uses ...      1. xupdate (by Petr Pajas) uses ...
54      XML::XUpdate::LibXML - Simple implementation of XUpdate format      XML::XUpdate::LibXML - Simple implementation of XUpdate format
# Line 49  XML::XUpdate::XSLT - A perl module for u Line 63  XML::XUpdate::XSLT - A perl module for u
63      2. This xupdate attempts to implement the XUpdate specs using XSLT only.      2. This xupdate attempts to implement the XUpdate specs using XSLT only.
64            
65    
66  =head3 Yet another xupdate - facts in short:  =head4 Yet another xupdate - facts in short:
67    
68    S: It would be nice to have a pure perl thingy which does (almost) the same stuff....    S: It would be nice to have a pure perl thingy which does (almost) the same stuff....
69        
# Line 60  XML::XUpdate::XSLT - A perl module for u Line 74  XML::XUpdate::XSLT - A perl module for u
74        
75    Q: Can we mimic/use the interface of the - already established - 'xupdate' program???    Q: Can we mimic/use the interface of the - already established - 'xupdate' program???
76        
77    Q: Should we follow the CRUD path first? (CRUD means: Create, Retrieve, Update, Delete)    Q: Should we follow the CRUD path first?
78          (CRUD is the acronym for the datastore action primitives: Create, Retrieve, Update, Delete)
79    S?: Proposal: XML::XUpdate::XSLT::API uses XML::XUpdate::XSLT::CRUD    S?: Proposal: XML::XUpdate::XSLT::API uses XML::XUpdate::XSLT::CRUD
80    
81    
82  =head4 Todo  =head3 References
83    
84        - XUpdate:
85          Requirements: http://www.xmldb.org/xupdate/xupdate-req.html
86          Working Draft: http://www.xmldb.org/xupdate/xupdate-wd.html
87        - XML API:
88        - XML::XUpdate::LibXML: http://search.cpan.org/author/PAJAS/XML-XUpdate-LibXML-0.4.0/lib/XML/XUpdate/LibXML.pm
89        - XSL / XSLT:
90          http://www.w3.org/TR/xslt
91          http://www.xsl-rp.de/
92          http://xml.klute-thiemann.de/w3c-de/REC-xslt-20020318/
93          http://xmlxslt.sourceforge.net/
94        - misc pointers:
95          "Re: Modify XML documents": http://aspn.activestate.com/ASPN/Mail/Message/perl-xml/1265431
96          XSL Extensions: http://xmlsoft.org/XSLT/extensions.html
97          EXSLT: http://www.exslt.org/set/functions/difference/index.html
98          "how to insert element at required position in document tree?": http://p2p.wrox.com/archive/xslt/2001-06/98.asp
99          XML APIs for Databases: http://www.javaworld.com/javaworld/jw-01-2000/jw-01-dbxml.html
100    
101    
102    =head3 Todo
103    
104    o What about proper encoding? (ISO-8859-1 or UTF-8)    o What about proper encoding? (ISO-8859-1 or UTF-8)
105    o Is it possible to create the required "xsl_template.xml" at runtime via XSL itself?    o Is it possible to create the required "xsl_template.xml" at runtime via XSL itself?
106    o Cache contents of external files (*.xml). Performance!    o Cache contents of external files (*.xml). Performance!
107      o Can exception / error-code handling be improved somehow?
108          Esp.: It would be interesting, if the XUpdate payload actually could be applied, or not...
109      o Conditional processing: <xupdate:if>, etc.
110        
111    
112  =cut  =cut
# Line 81  package XML::XUpdate::XSLT; Line 119  package XML::XUpdate::XSLT;
119  use strict;  use strict;
120  use warnings;  use warnings;
121    
 use XML::XSLT 0.41;  
 use Carp;  
 use File::Basename;  
122  use Data::Dumper;  use Data::Dumper;
123    use File::Basename;
124    use XML::XSLT 0.41;
125    use XML::XUpdate::Rewrite;
126    
127  # Namespace constants  # Namespace constants
128    
# Line 153  sub process { Line 191  sub process {
191  }  }
192    
193  # First, translate the xupdate payload to xsl.  # First, translate the xupdate payload to xsl.
194  # FIXME: do DOM only!  # FIXME: do DOM only! (don't use "->toString")
195  sub _calculate {  sub _calculate {
196    my $self = shift;    my $self = shift;
197    $self->{XSLT_ENGINE_PREP} = XML::XSLT->new(    $self->{XSLT_ENGINE_PREP} = XML::XSLT->new(
# Line 170  sub _calculate { Line 208  sub _calculate {
208  # FIXME: do DOM only!  # FIXME: do DOM only!
209  sub _apply {  sub _apply {
210    my $self = shift;    my $self = shift;
211    #print $self->get_stylesheet("_worker"), "\n";    
212      # debug - print the calculated xsl on STDERR
213      print STDERR $self->get_stylesheet("_worker"), "\n";
214      
215    #return;    #return;
216    $self->{XSLT_ENGINE_LIVE} = XML::XSLT->new(    $self->{XSLT_ENGINE_LIVE} = XML::XSLT->new(
217      Source => $self->get_stylesheet("_worker"),      Source => $self->get_stylesheet("_worker"),
# Line 184  sub _apply { Line 225  sub _apply {
225        
226  sub toString {  sub toString {
227    my $self = shift;    my $self = shift;
228    return $self->{XML}->{result};    
229      # use rest of argument list as hash of option values
230      my $options = {@_};
231      
232      # short circuit - just return what we have - don't modify anything
233      return $self->{XML}->{result} unless $options and $options->{rewrite};
234      
235      # Rewrite the xml document with certain engine to desired style.
236      # 'engine' defaults to "XMLParser" if not specified.
237      my $rewrite = XML::XUpdate::Rewrite->new( style => $options->{mode}, engine => $options->{using} );
238      $rewrite->set_document( $self->{XML}->{result} );
239      # TODO: Implement a configurable fallback here to return the un-rewritten payload if desired.
240      $rewrite->process() or die(__PACKAGE__ . ": Error while rewriting XML document.");
241      return $rewrite->get_document();
242  }  }
243    
244    
245  ######################################################################  ######################################################################
246  # AUXILIARY METHODS  # AUXILIARY METHODS
247    
248  # Argument parsing (with backwards compatibility hook).  # Argument list parsing.
249    # ... from XML::XUpdate::LibXML (w/o backwards compatibility hook).
250    # Could this make up a Class::AutoFill::__read_arglist which transparently
251    # makes object attributes from constructor arguments in a configurable way?
252  sub __parse_args {  sub __parse_args {
253    my $self = shift;    my $self = shift;
254    my %args;    my %args;
255    
256    if(@_ % 2 ) {    if ( @_ % 2 ) {
257      $args{dummy} = shift;      $args{dummy} = shift;
258      %args = (%args, @_);      %args = (%args, @_);
259    } else {    } else {
# Line 222  sub __slurp_file { Line 279  sub __slurp_file {
279    if (! -e $filename) {    if (! -e $filename) {
280      $filename = dirname(__FILE__) . "/$filename";      $filename = dirname(__FILE__) . "/$filename";
281      if (! -e $filename) {      if (! -e $filename) {
282        croak("File $filename does not exist.");        die("File $filename does not exist.");
283      }      }
284    }    }
285        

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.7

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed