ruby-xslt 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +3 -0
- data/ChangeLog +8 -0
- data/README +30 -20
- data/examples/fuzface.rb +1 -1
- data/examples/fuzface_REXML.rb +2 -2
- data/examples/fuzface_XML-Simple.rb +1 -1
- data/examples/fuzface_data.rb +1 -1
- data/examples/fuzface_error.rb +1 -1
- data/examples/fuzface_to_s.rb +1 -1
- data/examples/info.rb +1 -1
- data/examples/test_functions.rb +1 -1
- data/examples/test_parameters.rb +1 -1
- data/extconf.rb +33 -68
- data/extfunc.c +7 -15
- data/parser.c +0 -33
- data/ruby-xslt.gemspec +3 -3
- data/tests/test.rb +140 -43
- data/xslt.h +2 -2
- data/{xslt.c → xslt_lib.c} +15 -44
- metadata +5 -4
data/AUTHORS
CHANGED
@@ -14,6 +14,9 @@ Brendan Taylor <whateley at gmail dot com>
|
|
14
14
|
<kiyoya at gmail dot com>
|
15
15
|
* Add definitions for some error classes and sets libxml error function
|
16
16
|
|
17
|
+
Pau Garcia i Quiles <pgquiles at elpauer dot org>
|
18
|
+
* gemspec
|
19
|
+
|
17
20
|
== Thanks to :
|
18
21
|
|
19
22
|
knu <knu at freebsd dot org> for FreeBSD port (see http://www.freshports.org/textproc/ruby-xslt/)
|
data/ChangeLog
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
0.9.3 :
|
2
|
+
* Due to recent changes in Gentoo Linux's install system, ruby-xslt no longer installs correctly. Brendan fixed this.
|
3
|
+
* Cleaned up extconf.rb
|
4
|
+
* Removed unused debugging code (memwatch)
|
5
|
+
* Moved some things out of C into Ruby
|
6
|
+
* Made error handling much more useful
|
7
|
+
* Added some unit tests
|
8
|
+
|
1
9
|
0.9.2 :
|
2
10
|
* Changes to the way XSLT files are loaded, so that we can keep their base URI straight - Sorry Brendan !!!
|
3
11
|
* Major corrections
|
data/README
CHANGED
@@ -17,9 +17,10 @@ This program is distributed without any warranty. See the file
|
|
17
17
|
== DOWNLOAD
|
18
18
|
|
19
19
|
=== Last version
|
20
|
-
* version 0.9.
|
20
|
+
* version 0.9.3[http://gregoire.lejeune.free.fr/ruby-xslt_0.9.3.tar.gz]
|
21
21
|
|
22
22
|
=== Old versions
|
23
|
+
* version 0.9.2[http://gregoire.lejeune.free.fr/ruby-xslt_0.9.2.tar.gz]
|
23
24
|
* version 0.9.1[http://gregoire.lejeune.free.fr/ruby-xslt_0.9.1.tar.gz]
|
24
25
|
* version 0.8.2[http://gregoire.lejeune.free.fr/ruby-xslt_0.8.2.tar.gz]
|
25
26
|
* version 0.8.1[http://gregoire.lejeune.free.fr/ruby-xslt_0.8.1.tar.gz]
|
@@ -57,14 +58,10 @@ See this page[http://rubyforge.org/scm/?group_id=423] for more informations
|
|
57
58
|
--with-xslt-dir=PATH specify the directory name for the libxslt include
|
58
59
|
files and/or library
|
59
60
|
|
60
|
-
--
|
61
|
-
|
62
|
-
be accessed with the class method XML::XSLT.errors
|
63
|
-
(will change in a future version)
|
61
|
+
--disable-error-handler disables the new error handler
|
62
|
+
|
64
63
|
--disable-exslt disables libexslt support <http://exslt.org/>
|
65
64
|
|
66
|
-
--enable-debug compile with memwatch
|
67
|
-
<http://www.linkdata.se/sourcecode.html>
|
68
65
|
|
69
66
|
== EXAMPLES
|
70
67
|
|
@@ -84,8 +81,8 @@ See this page[http://rubyforge.org/scm/?group_id=423] for more informations
|
|
84
81
|
|
85
82
|
xslt = XML::XSLT.new()
|
86
83
|
|
87
|
-
xslt.xml = REXML::Document.new File.
|
88
|
-
xslt.xsl = REXML::Document.new File.
|
84
|
+
xslt.xml = REXML::Document.new File.read( "test.xml" )
|
85
|
+
xslt.xsl = REXML::Document.new File.read( "test.xsl" )
|
89
86
|
|
90
87
|
out = xslt.serve()
|
91
88
|
print out;
|
@@ -119,19 +116,32 @@ See this page[http://rubyforge.org/scm/?group_id=423] for more informations
|
|
119
116
|
=== External functions support
|
120
117
|
require "xml/xslt"
|
121
118
|
|
122
|
-
class XML::XSLT
|
123
|
-
def round_trip( arg )
|
124
|
-
arg
|
125
|
-
end
|
126
|
-
def type( arg )
|
127
|
-
arg.class.to_s
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
119
|
xslt = XML::XSLT.new()
|
132
120
|
xslt.xsl = "functions.xsl"
|
133
121
|
xslt.xml = "test.xml"
|
134
|
-
|
135
|
-
XML::XSLT.
|
122
|
+
|
123
|
+
XML::XSLT.registerExtFunc("http://test.none", "round-trip") do |arg|
|
124
|
+
arg
|
125
|
+
end
|
126
|
+
|
127
|
+
XML::XSLT.registerExtFunc("http://test.none", "type") do |arg|
|
128
|
+
arg.class.to_s
|
129
|
+
end
|
136
130
|
|
137
131
|
print xslt.serve
|
132
|
+
|
133
|
+
=== Error handling
|
134
|
+
|
135
|
+
XML::XSLT.registerErrorHandler { |string| puts string }
|
136
|
+
|
137
|
+
xslt = XML::XSLT.new
|
138
|
+
xslt.xml = "not xml"
|
139
|
+
|
140
|
+
This fragment would print:
|
141
|
+
|
142
|
+
Entity: line 1:
|
143
|
+
parser
|
144
|
+
error :
|
145
|
+
Start Tag expected, '<' not found
|
146
|
+
not xml
|
147
|
+
^
|
data/examples/fuzface.rb
CHANGED
data/examples/fuzface_REXML.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/ruby -w
|
2
2
|
require 'rexml/document'
|
3
|
-
require '
|
3
|
+
require 'xml/xslt'
|
4
4
|
|
5
5
|
xslt = XML::XSLT.new()
|
6
6
|
|
@@ -8,4 +8,4 @@ xslt.xml = REXML::Document.new File.open( "fuzface.xml" )
|
|
8
8
|
xslt.xsl = REXML::Document.new File.open( "fuzface.xsl" )
|
9
9
|
|
10
10
|
out = xslt.serve()
|
11
|
-
puts out
|
11
|
+
puts out
|
data/examples/fuzface_data.rb
CHANGED
data/examples/fuzface_error.rb
CHANGED
data/examples/fuzface_to_s.rb
CHANGED
data/examples/info.rb
CHANGED
data/examples/test_functions.rb
CHANGED
data/examples/test_parameters.rb
CHANGED
data/extconf.rb
CHANGED
@@ -17,98 +17,63 @@ Configuration:
|
|
17
17
|
--with-xslt-dir=PATH specify the directory name for the libxslt include
|
18
18
|
files and/or library
|
19
19
|
|
20
|
-
--
|
21
|
-
are appended to the class variable XML::XSLT and can
|
22
|
-
be accessed with the class method XML::XSLT.errors
|
23
|
-
(will change in a future version)
|
24
|
-
--disable-exslt disables libexslt support <http://exslt.org/>
|
20
|
+
--disable-error-handler disables the new error handler
|
25
21
|
|
26
|
-
--
|
27
|
-
<http://www.linkdata.se/sourcecode.html>
|
28
|
-
|
22
|
+
--disable-exslt disables libexslt support <http://exslt.org/>
|
29
23
|
HELP
|
30
24
|
end
|
31
25
|
|
32
|
-
if ARGV.include?( "--help" )
|
26
|
+
if ARGV.include?( "--help" ) or ARGV.include?( "-h" )
|
33
27
|
help()
|
34
28
|
exit 0
|
35
29
|
end
|
36
30
|
|
37
|
-
if enable_config("
|
38
|
-
File.symlink( "debug/memwatch.h", "memwatch.h" ) if( ! File.exist?("memwatch.h") )
|
39
|
-
File.symlink( "debug/memwatch.c", "memwatch.c" ) if( ! File.exist?("memwatch.c") )
|
40
|
-
$CFLAGS += " -DMEMWATCH -D__DEBUG__"
|
41
|
-
end
|
42
|
-
|
43
|
-
if enable_config("error-handler", false)
|
31
|
+
if enable_config("error-handler", true)
|
44
32
|
$CFLAGS += " -DUSE_ERROR_HANDLER"
|
45
33
|
end
|
46
34
|
|
47
|
-
|
35
|
+
#$LIBPATH.push(Config::CONFIG['libdir'])
|
48
36
|
|
49
37
|
def crash(str)
|
50
38
|
printf(" extconf failure: %s\n", str)
|
51
39
|
exit 1
|
52
40
|
end
|
53
41
|
|
54
|
-
|
55
|
-
|
56
|
-
#else
|
57
|
-
# $defs.push('-DHAVE_ZLIB_H')
|
58
|
-
#end
|
59
|
-
|
60
|
-
if dir_config( "xslt" ) != [nil, nil]
|
61
|
-
inc, lib = dir_config( 'xslt' )
|
62
|
-
$LDFLAGS << " -L#{lib} -lxslt -lxml2 -lz -lpthread -liconv -lm"
|
63
|
-
$CFLAGS << " -I#{inc}"
|
64
|
-
elsif ex = find_executable( "xslt-config" )
|
65
|
-
$LDFLAGS << ' ' + `#{ex} --libs`.chomp
|
66
|
-
$CFLAGS << ' ' + `#{ex} --cflags`.chomp
|
67
|
-
else
|
68
|
-
crash(<<EOL)
|
69
|
-
need libxslt.
|
42
|
+
dir_config( 'xml2' )
|
43
|
+
dir_config( 'xslt' )
|
70
44
|
|
71
|
-
|
72
|
-
|
73
|
-
--with-xslt-lib=/path/to/libxslt/lib
|
74
|
-
--with-xslt-include=/path/to/libxslt/include
|
75
|
-
EOL
|
76
|
-
end
|
45
|
+
have_library "xml2", "xmlParseDoc" || crash("need libxml2")
|
46
|
+
have_library "xslt", "xsltParseStylesheetFile" || crash("need libxslt")
|
77
47
|
|
78
48
|
if enable_config("exslt", true)
|
79
|
-
|
49
|
+
have_library "exslt", "exsltRegisterAll"
|
80
50
|
$CFLAGS += " -DUSE_EXSLT"
|
81
51
|
end
|
82
52
|
|
83
|
-
$CFLAGS = '-g -Wall ' + $CFLAGS
|
84
|
-
|
85
|
-
puts "compile with : "
|
86
|
-
puts " CFLAGS = #{$CFLAGS}"
|
87
|
-
puts " LDFLAGS = #{$LDFLAGS}"
|
88
|
-
puts
|
53
|
+
$CFLAGS = '-g -Wall ' + `xml2-config --cflags`.chomp + " " + `xslt-config --cflags`.chomp + " " + $CFLAGS
|
89
54
|
|
90
55
|
create_header()
|
91
|
-
create_makefile("xml/
|
56
|
+
create_makefile("xml/xslt_lib")
|
92
57
|
|
93
|
-
###### Modify Makefile: #######
|
94
58
|
File.rename( "Makefile", "Makefile.orig" )
|
95
|
-
|
96
|
-
|
97
|
-
oldmkfl.each_line
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
59
|
+
File.open( "Makefile.orig" ) do |oldmkfl|
|
60
|
+
File.open( "Makefile", "w" ) do |newmkfl|
|
61
|
+
oldmkfl.each_line do |line|
|
62
|
+
case(line)
|
63
|
+
when /^all:/
|
64
|
+
newmkfl.puts(line)
|
65
|
+
newmkfl.puts("")
|
66
|
+
newmkfl.puts("test: all") # insert the "test" target
|
67
|
+
newmkfl.puts("\t\t@cd tests && ruby test.rb && cd ..")
|
68
|
+
newmkfl.puts("doc: all") # insert the "doc" target
|
69
|
+
newmkfl.puts("\t\t@rdoc -S -t \"Ruby/XSLT Documentation\" README AUTHORS ChangeLog xslt_lib.c lib/xslt.rb")
|
70
|
+
when /^distclean:/
|
71
|
+
newmkfl.puts(line)
|
72
|
+
newmkfl.puts("\t\t@-$(RM) Makefile.orig")
|
73
|
+
newmkfl.puts("\t\t@-$(RM)r doc")
|
74
|
+
else
|
75
|
+
newmkfl.puts(line)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/extfunc.c
CHANGED
@@ -175,42 +175,34 @@ xmlXPathObjectPtr value2xpathObj (VALUE val) {
|
|
175
175
|
*/
|
176
176
|
void xmlXPathFuncCallback( xmlXPathParserContextPtr ctxt, int nargs) {
|
177
177
|
VALUE result, arguments[nargs];
|
178
|
-
VALUE ns_hash, func_hash,
|
179
|
-
const xmlChar *namespace;
|
180
|
-
char *rb_func, *chr;
|
178
|
+
VALUE ns_hash, func_hash, block;
|
179
|
+
const xmlChar *namespace, *name;
|
181
180
|
xmlXPathObjectPtr obj;
|
182
181
|
int i;
|
183
182
|
|
184
183
|
if (ctxt == NULL || ctxt->context == NULL)
|
185
184
|
return;
|
186
185
|
|
187
|
-
|
186
|
+
name = ctxt->context->function;
|
188
187
|
namespace = ctxt->context->functionURI;
|
189
188
|
|
190
189
|
ns_hash = rb_cvar_get(cXSLT, rb_intern("@@extFunctions"));
|
191
|
-
|
190
|
+
|
192
191
|
func_hash = rb_hash_aref(ns_hash, rb_str_new2((char *)namespace));
|
193
192
|
|
194
193
|
if(func_hash == Qnil) {
|
195
|
-
rb_warning( "xmlXPathFuncCallback: namespace %s not
|
194
|
+
rb_warning( "xmlXPathFuncCallback: namespace %s not registered!\n", namespace );
|
196
195
|
}
|
197
196
|
|
198
|
-
|
197
|
+
block = rb_hash_aref(func_hash, rb_str_new2((char *)name));
|
199
198
|
|
200
199
|
for (i = nargs - 1; i >= 0; i--) {
|
201
200
|
obj = valuePop(ctxt);
|
202
201
|
arguments[i] = xpathObj2value(obj, ctxt->context->doc);
|
203
202
|
}
|
204
203
|
|
205
|
-
|
206
|
-
while( (chr = strchr(rb_func, '-')) != NULL ) {
|
207
|
-
chr[0] = '_'; /* so we pretend the - was a _ all along */
|
208
|
-
}
|
209
|
-
|
210
|
-
result = rb_funcall2( object, rb_intern(rb_func), nargs, arguments);
|
204
|
+
result = rb_funcall2( block, rb_intern("call"), nargs, arguments);
|
211
205
|
|
212
|
-
free( rb_func );
|
213
|
-
|
214
206
|
obj = value2xpathObj(result);
|
215
207
|
valuePush(ctxt, obj);
|
216
208
|
}
|
data/parser.c
CHANGED
@@ -24,11 +24,6 @@ extern VALUE cXSLT;
|
|
24
24
|
xmlDocPtr parse_xml( char* xml, int iXmlType ) {
|
25
25
|
xmlDocPtr tXMLDocument = NULL;
|
26
26
|
|
27
|
-
#ifdef USE_ERROR_HANDLER
|
28
|
-
VALUE error_arr = rb_cvar_get(cXSLT, rb_intern("@@errors"));
|
29
|
-
int iInitialNumberOfErrors = RARRAY(error_arr)->len;
|
30
|
-
#endif
|
31
|
-
|
32
27
|
/** Act: Parse XML */
|
33
28
|
if( iXmlType == RUBY_XSLT_XMLSRC_TYPE_STR ) {
|
34
29
|
tXMLDocument = xmlParseMemory( xml, strlen( xml ) );
|
@@ -41,12 +36,6 @@ xmlDocPtr parse_xml( char* xml, int iXmlType ) {
|
|
41
36
|
return( NULL );
|
42
37
|
}
|
43
38
|
|
44
|
-
#ifdef USE_ERROR_HANDLER
|
45
|
-
if(RARRAY(error_arr)->len > iInitialNumberOfErrors) {
|
46
|
-
rb_raise( eXSLTTransformationError, "Stylesheet transformation error" );
|
47
|
-
}
|
48
|
-
#endif
|
49
|
-
|
50
39
|
return( tXMLDocument );
|
51
40
|
}
|
52
41
|
|
@@ -58,11 +47,6 @@ xsltStylesheetPtr parse_xsl( char* xsl, int iXslType ) {
|
|
58
47
|
xmlCharEncodingHandlerPtr encoder = NULL;
|
59
48
|
const xmlChar *encoding = NULL;
|
60
49
|
|
61
|
-
#ifdef USE_ERROR_HANDLER
|
62
|
-
VALUE error_arr = rb_cvar_get(cXSLT, rb_intern("@@errors"));
|
63
|
-
int iInitialNumberOfErrors = RARRAY(error_arr)->len;
|
64
|
-
#endif
|
65
|
-
|
66
50
|
/** Act: Encoding support */
|
67
51
|
xmlInitCharEncodingHandlers( );
|
68
52
|
|
@@ -95,12 +79,6 @@ xsltStylesheetPtr parse_xsl( char* xsl, int iXslType ) {
|
|
95
79
|
}
|
96
80
|
}
|
97
81
|
|
98
|
-
#ifdef USE_ERROR_HANDLER
|
99
|
-
if(RARRAY(error_arr)->len > iInitialNumberOfErrors) {
|
100
|
-
rb_raise( eXSLTTransformationError, "Stylesheet transformation error" );
|
101
|
-
}
|
102
|
-
#endif
|
103
|
-
|
104
82
|
return( tParsedXslt );
|
105
83
|
}
|
106
84
|
|
@@ -113,11 +91,6 @@ char* parse( xsltStylesheetPtr tParsedXslt, xmlDocPtr tXMLDocument, char **pxPar
|
|
113
91
|
xmlChar *tXMLDocumentResultString;
|
114
92
|
int tXMLDocumentResultLenght;
|
115
93
|
|
116
|
-
#ifdef USE_ERROR_HANDLER
|
117
|
-
VALUE error_arr = rb_cvar_get(cXSLT, rb_intern("@@errors"));
|
118
|
-
int iInitialNumberOfErrors = RARRAY(error_arr)->len;
|
119
|
-
#endif
|
120
|
-
|
121
94
|
tXMLDocumentResult = xsltApplyStylesheet( tParsedXslt, tXMLDocument, (const char**) pxParams );
|
122
95
|
if( tXMLDocumentResult == NULL ) {
|
123
96
|
rb_raise( eXSLTTransformationError, "Stylesheet transformation error" );
|
@@ -128,12 +101,6 @@ char* parse( xsltStylesheetPtr tParsedXslt, xmlDocPtr tXMLDocument, char **pxPar
|
|
128
101
|
|
129
102
|
xmlFreeDoc(tXMLDocumentResult);
|
130
103
|
|
131
|
-
#ifdef USE_ERROR_HANDLER
|
132
|
-
if(RARRAY(error_arr)->len > iInitialNumberOfErrors) {
|
133
|
-
rb_raise( eXSLTTransformationError, "Stylesheet transformation error" );
|
134
|
-
}
|
135
|
-
#endif
|
136
|
-
|
137
104
|
return((char*)tXMLDocumentResultString);
|
138
105
|
}
|
139
106
|
|
data/ruby-xslt.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{ruby-xslt}
|
3
|
-
s.version = "0.9.
|
3
|
+
s.version = "0.9.3"
|
4
4
|
s.date = %q{2005-11-17}
|
5
5
|
s.summary = %q{A Ruby class for processing XSLT}
|
6
|
-
s.email = %q{
|
6
|
+
s.email = %q{gregoire.lejeune@free.fr}
|
7
7
|
s.homepage = %q{http://raa.ruby-lang.org/project/ruby-xslt/}
|
8
8
|
s.description = %q{Ruby/XSLT is a simple XSLT class based on libxml <http://xmlsoft.org/> and libxslt <http://xmlsoft.org/XSLT/>}
|
9
9
|
s.has_rdoc = true
|
@@ -16,4 +16,4 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.rdoc_options = ["--title", "Ruby/XSLT", "--main", "README", "--line-numbers"]
|
17
17
|
s.extra_rdoc_files = ["README", "AUTHORS", "COPYING", "ChangeLog"]
|
18
18
|
s.extensions = ["extconf.rb"]
|
19
|
-
end
|
19
|
+
end
|
data/tests/test.rb
CHANGED
@@ -1,32 +1,57 @@
|
|
1
1
|
#!ruby
|
2
2
|
|
3
3
|
require "test/unit"
|
4
|
-
require "../xslt"
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
#
|
9
|
-
#
|
5
|
+
$LOAD_PATH << '..'
|
6
|
+
|
7
|
+
# this is ugly, but it's the only way I can think of
|
8
|
+
# (lib/xslt.rb requires xml/xslt_lib.so, so we copy it and delete when done)
|
9
|
+
require "ftools"
|
10
|
+
Dir.mkdir "../xml"
|
11
|
+
|
12
|
+
begin
|
13
|
+
File.copy "../xslt_lib.so", "../xml"
|
14
|
+
rescue
|
15
|
+
begin
|
16
|
+
File.copy "../xslt_lib.bundle", "../xml"
|
17
|
+
rescue
|
18
|
+
raise
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
require "lib/xslt"
|
23
|
+
begin
|
24
|
+
File.delete "../xml/xslt_lib.so"
|
25
|
+
rescue
|
26
|
+
begin
|
27
|
+
File.delete "../xml/xslt_lib.bundle"
|
28
|
+
rescue
|
29
|
+
raise
|
30
|
+
end
|
31
|
+
end
|
32
|
+
Dir.rmdir "../xml"
|
33
|
+
|
34
|
+
EXT_FUNC_XSL =<<END
|
35
|
+
<xsl:stylesheet
|
36
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
37
|
+
xmlns:ext="http://necronomicorp.com/nil"
|
38
|
+
version="1.0">
|
39
|
+
|
40
|
+
<xsl:template match="/">
|
41
|
+
<xsl:value-of select="ext:foo()"/>
|
42
|
+
</xsl:template>
|
43
|
+
|
44
|
+
</xsl:stylesheet>
|
45
|
+
END
|
10
46
|
|
11
47
|
class XsltTest < Test::Unit::TestCase
|
12
48
|
def setup
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
rescue LoadError => e
|
20
|
-
@xml_simple = false
|
21
|
-
end
|
22
|
-
|
23
|
-
@xml_smart = true
|
24
|
-
begin
|
25
|
-
require "xml/smart"
|
26
|
-
rescue LoadError => e
|
27
|
-
@xml_smart = false
|
28
|
-
end
|
29
|
-
end
|
49
|
+
@xslt = XML::XSLT.new( )
|
50
|
+
|
51
|
+
@testOut = "<?xml version=\"1.0\"?>\nThis is a test file\n"
|
52
|
+
|
53
|
+
@errors = []
|
54
|
+
XML::XSLT.registerErrorHandler { |s| @errors << s }
|
30
55
|
end
|
31
56
|
|
32
57
|
def test_instance
|
@@ -36,72 +61,128 @@ class XsltTest < Test::Unit::TestCase
|
|
36
61
|
def test_from_file
|
37
62
|
@xslt.xml = "t.xml"
|
38
63
|
@xslt.xsl = "t.xsl"
|
64
|
+
|
39
65
|
out = @xslt.serve
|
40
66
|
assert_equal( @testOut, out )
|
67
|
+
assert_equal( [], @errors )
|
41
68
|
end
|
42
69
|
|
43
70
|
def test_from_data
|
44
|
-
@xslt.xml =
|
45
|
-
@xslt.xsl =
|
71
|
+
@xslt.xml = File.read( "t.xml" )
|
72
|
+
@xslt.xsl = File.read( "t.xsl" )
|
73
|
+
|
46
74
|
out = @xslt.serve
|
47
75
|
assert_equal( @testOut, out )
|
76
|
+
assert_equal( [], @errors )
|
48
77
|
end
|
49
78
|
|
50
79
|
def test_from_simple
|
51
|
-
|
52
|
-
require
|
80
|
+
begin
|
81
|
+
require "xml/simple"
|
82
|
+
|
53
83
|
@xslt.xml = XML::Simple.open( "t.xml" )
|
54
84
|
@xslt.xsl = XML::Simple.open( "t.xsl" )
|
85
|
+
|
55
86
|
out = @xslt.serve()
|
56
87
|
assert_equal( @testOut, out )
|
57
|
-
|
58
|
-
|
88
|
+
assert_equal( [], @errors )
|
89
|
+
rescue LoadError => e
|
90
|
+
# just skip it
|
59
91
|
end
|
60
92
|
end
|
61
93
|
|
62
94
|
def test_from_smart
|
63
|
-
|
64
|
-
require
|
95
|
+
begin
|
96
|
+
require "xml/smart"
|
97
|
+
|
65
98
|
@xslt.xml = XML::Smart.open( "t.xml" )
|
66
99
|
@xslt.xsl = XML::Smart.open( "t.xsl" )
|
100
|
+
|
67
101
|
out = @xslt.serve()
|
68
102
|
assert_equal( @testOut, out )
|
69
|
-
|
70
|
-
|
103
|
+
assert_equal( [], @errors )
|
104
|
+
rescue LoadError => e
|
105
|
+
# just skip it
|
71
106
|
end
|
72
107
|
end
|
73
108
|
|
74
109
|
def test_from_rexml
|
75
110
|
require 'rexml/document'
|
76
|
-
@xslt.xml = REXML::Document.new File.
|
77
|
-
@xslt.xsl = REXML::Document.new File.
|
111
|
+
@xslt.xml = REXML::Document.new File.read( "t.xml" )
|
112
|
+
@xslt.xsl = REXML::Document.new File.read( "t.xsl" )
|
113
|
+
|
78
114
|
out = @xslt.serve()
|
115
|
+
assert_equal( [], @errors )
|
79
116
|
assert_equal( @testOut, out )
|
80
117
|
end
|
81
118
|
|
82
119
|
def test_error_1
|
83
|
-
|
120
|
+
assert_raises(XML::XSLT::ParsingError) do
|
84
121
|
@xslt.xsl = "nil"
|
85
|
-
rescue => e
|
86
|
-
assert_instance_of( XML::XSLT::ParsingError, e )
|
87
122
|
end
|
123
|
+
|
124
|
+
errors = ["Entity: line 1: ",
|
125
|
+
"parser ",
|
126
|
+
"error : ",
|
127
|
+
"Start tag expected, '<' not found\n",
|
128
|
+
"nil\n",
|
129
|
+
"^\n"]
|
130
|
+
|
131
|
+
assert_equal( errors, @errors )
|
88
132
|
end
|
89
133
|
|
90
134
|
def test_error_2
|
91
|
-
|
135
|
+
assert_raises(XML::XSLT::ParsingError) do
|
92
136
|
@xslt.xml = "nil"
|
93
|
-
rescue => e
|
94
|
-
assert_instance_of( XML::XSLT::ParsingError, e )
|
95
137
|
end
|
138
|
+
|
139
|
+
errors = ["Entity: line 1: ",
|
140
|
+
"parser ",
|
141
|
+
"error : ",
|
142
|
+
"Start tag expected, '<' not found\n",
|
143
|
+
"nil\n",
|
144
|
+
"^\n"]
|
145
|
+
|
146
|
+
assert_equal( errors, @errors )
|
96
147
|
end
|
97
148
|
|
149
|
+
# this test fails (any reason that it *should* raise an error?)
|
150
|
+
=begin
|
98
151
|
def test_error_3
|
99
|
-
|
152
|
+
assert_raises(XML::XSLT::ParsingError) do
|
100
153
|
@xslt.xml = "t.xsl"
|
101
|
-
rescue => e
|
102
|
-
assert_instance_of( XML::XSLT::ParsingError, e )
|
103
154
|
end
|
104
155
|
end
|
156
|
+
=end
|
157
|
+
|
158
|
+
def test_transformation_error
|
159
|
+
@xslt.xml = "<test/>"
|
160
|
+
# substitute so that the function is guaranteed to not be registered
|
161
|
+
@xslt.xsl = EXT_FUNC_XSL.sub( /foo/, "bar")
|
162
|
+
|
163
|
+
assert_raises(XML::XSLT::TransformationError) do
|
164
|
+
@xslt.serve
|
165
|
+
end
|
166
|
+
|
167
|
+
errors = ["xmlXPathCompOpEval: function bar not found\n",
|
168
|
+
"Unregistered function\n",
|
169
|
+
"xmlXPathCompiledEval: evaluation failed\n",
|
170
|
+
"runtime error: element value-of\n",
|
171
|
+
"xsltValueOf: text copy failed\n"]
|
172
|
+
assert_equal(errors, @errors)
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_external_function
|
176
|
+
@xslt.xml = "<test/>"
|
177
|
+
@xslt.xsl = EXT_FUNC_XSL
|
178
|
+
|
179
|
+
XML::XSLT.registerExtFunc("http://necronomicorp.com/nil", "foo") do
|
180
|
+
"success!"
|
181
|
+
end
|
182
|
+
|
183
|
+
assert_equal("<?xml version=\"1.0\"?>\nsuccess!\n", @xslt.serve())
|
184
|
+
assert_equal([], @errors)
|
185
|
+
end
|
105
186
|
|
106
187
|
def test_base_uri_1
|
107
188
|
@xslt.xml = "<test/>"
|
@@ -111,6 +192,8 @@ class XsltTest < Test::Unit::TestCase
|
|
111
192
|
assert_nothing_raised( XML::XSLT::ParsingError ) do
|
112
193
|
@xslt.xsl = xsl
|
113
194
|
end
|
195
|
+
|
196
|
+
assert_equal( [], @errors )
|
114
197
|
end
|
115
198
|
|
116
199
|
def test_base_uri_2
|
@@ -121,5 +204,19 @@ class XsltTest < Test::Unit::TestCase
|
|
121
204
|
assert_raises( XML::XSLT::ParsingError ) do
|
122
205
|
@xslt.xsl = xsl
|
123
206
|
end
|
207
|
+
|
208
|
+
errors = ["I/O ",
|
209
|
+
"warning : ",
|
210
|
+
"failed to load external entity \"result.xsl\"\n",
|
211
|
+
"compilation error: element import\n",
|
212
|
+
"xsl:import : unable to load result.xsl\n"]
|
213
|
+
|
214
|
+
assert_equal( errors, @errors )
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_alias
|
218
|
+
assert_nothing_raised do
|
219
|
+
XML::XSLT.register_ext_func("http://necronomicorp.com/nil", "nil") {}
|
220
|
+
end
|
124
221
|
end
|
125
222
|
end
|
data/xslt.h
CHANGED
@@ -53,8 +53,8 @@
|
|
53
53
|
#include "parameters.h"
|
54
54
|
#include "extfunc.h"
|
55
55
|
|
56
|
-
#define RUBY_XSLT_VERSION "0.9.
|
57
|
-
#define RUBY_XSLT_VERNUM
|
56
|
+
#define RUBY_XSLT_VERSION "0.9.3"
|
57
|
+
#define RUBY_XSLT_VERNUM 093
|
58
58
|
|
59
59
|
#define RUBY_XSLT_XSLSRC_TYPE_NULL 0
|
60
60
|
#define RUBY_XSLT_XSLSRC_TYPE_STR 1
|
data/{xslt.c → xslt_lib.c}
RENAMED
@@ -358,27 +358,22 @@ VALUE ruby_xslt_save( VALUE self, VALUE xOutFilename ) {
|
|
358
358
|
* Brendan Taylor
|
359
359
|
* whateley@gmail.com
|
360
360
|
*/
|
361
|
-
|
362
|
-
*
|
363
|
-
*
|
364
|
-
* Return an Array containing all the xml errors
|
361
|
+
/*
|
362
|
+
* libxml2/libxslt error handling function
|
365
363
|
*
|
366
|
-
*
|
364
|
+
* converts the error to a String and passes it off to a block
|
365
|
+
* registered using XML::XSLT.register_error_handler
|
367
366
|
*/
|
368
|
-
|
369
|
-
return rb_cvar_get(class, rb_intern("@@errors"));
|
370
|
-
}
|
371
|
-
|
372
|
-
void xsltErrorFuncHandler(void *ctx, const char *msg, ...) {
|
367
|
+
void ruby_xslt_error_handler(void *ctx, const char *msg, ...) {
|
373
368
|
va_list ap;
|
374
369
|
char *str;
|
375
370
|
char *larger;
|
376
371
|
int chars;
|
377
372
|
int size = 150;
|
378
373
|
|
379
|
-
VALUE
|
374
|
+
VALUE block = rb_cvar_get(cXSLT, rb_intern("@@error_handler"));
|
380
375
|
|
381
|
-
/*
|
376
|
+
/* the following was cut&pasted from the libxslt python bindings */
|
382
377
|
str = (char *) xmlMalloc(150);
|
383
378
|
if (str == NULL)
|
384
379
|
return;
|
@@ -400,7 +395,7 @@ void xsltErrorFuncHandler(void *ctx, const char *msg, ...) {
|
|
400
395
|
str = larger;
|
401
396
|
}
|
402
397
|
|
403
|
-
|
398
|
+
rb_funcall( block, rb_intern("call"), 1, rb_str_new2(str));
|
404
399
|
}
|
405
400
|
#endif
|
406
401
|
|
@@ -473,27 +468,10 @@ VALUE ruby_xslt_media_type( VALUE self ) {
|
|
473
468
|
*/
|
474
469
|
|
475
470
|
/**
|
476
|
-
*
|
477
|
-
* registers an extension function "round-trip" in the namespace "http://test.none"
|
478
|
-
*
|
479
|
-
* when XPath like ex:round-trip(arg) is encountered in the XSLT it will call the method "round_trip" on the rbObj object with the argument arg
|
471
|
+
* internal use only.
|
480
472
|
*/
|
481
|
-
VALUE
|
482
|
-
|
483
|
-
|
484
|
-
ns_hash = rb_cvar_get(cXSLT, rb_intern("@@extFunctions"));
|
485
|
-
|
486
|
-
func_hash = rb_hash_aref(ns_hash, ns_uri);
|
487
|
-
|
488
|
-
if(func_hash == Qnil) {
|
489
|
-
/* we've seen no reference to this URI, so create one */
|
490
|
-
func_hash = rb_hash_new();
|
491
|
-
rb_hash_aset(ns_hash, ns_uri, func_hash);
|
492
|
-
}
|
493
|
-
|
494
|
-
rb_hash_aset(func_hash, name, receiver);
|
495
|
-
|
496
|
-
xsltRegisterExtModuleFunction( BAD_CAST STR2CSTR(name), BAD_CAST STR2CSTR(ns_uri), xmlXPathFuncCallback );
|
473
|
+
VALUE ruby_xslt_reg_function( VALUE class, VALUE namespace, VALUE name ) {
|
474
|
+
xsltRegisterExtModuleFunction( BAD_CAST STR2CSTR(name), BAD_CAST STR2CSTR(namespace), xmlXPathFuncCallback );
|
497
475
|
|
498
476
|
return Qnil;
|
499
477
|
}
|
@@ -555,7 +533,7 @@ VALUE ruby_xslt_to_s( VALUE self ) {
|
|
555
533
|
* ----------------------------------------------------------------------------
|
556
534
|
*/
|
557
535
|
|
558
|
-
void
|
536
|
+
void Init_xslt_lib( void ) {
|
559
537
|
mXML = rb_define_module( "XML" );
|
560
538
|
cXSLT = rb_define_class_under( mXML, "XSLT", rb_cObject );
|
561
539
|
|
@@ -581,11 +559,7 @@ void Init_xslt( void ) {
|
|
581
559
|
rb_define_const( cXSLT, "RUBY_XSLT_VERSION", rb_str_new2(RUBY_XSLT_VERSION) );
|
582
560
|
|
583
561
|
rb_define_singleton_method( cXSLT, "new", ruby_xslt_new, 0 );
|
584
|
-
rb_define_singleton_method( cXSLT, "
|
585
|
-
|
586
|
-
/* a hash of hashes. might be more elegant if it were its own class */
|
587
|
-
/* keeps track of what functions are registered in what namespaces */
|
588
|
-
rb_define_class_variable( cXSLT, "@@extFunctions", rb_hash_new());
|
562
|
+
rb_define_singleton_method( cXSLT, "registerFunction", ruby_xslt_reg_function, 2);
|
589
563
|
|
590
564
|
rb_define_method( cXSLT, "serve", ruby_xslt_serve, 0 );
|
591
565
|
rb_define_method( cXSLT, "save", ruby_xslt_save, 1 );
|
@@ -606,11 +580,8 @@ void Init_xslt( void ) {
|
|
606
580
|
rb_define_method( cXSLT, "mediaType", ruby_xslt_media_type, 0 );
|
607
581
|
|
608
582
|
#ifdef USE_ERROR_HANDLER
|
609
|
-
|
610
|
-
|
611
|
-
xsltSetGenericErrorFunc( NULL, xsltErrorFuncHandler );
|
612
|
-
rb_define_class_variable( cXSLT, "@@errors", rb_ary_new());
|
613
|
-
rb_define_singleton_method( cXSLT, "errors", rb_xslt_errors, 0 );
|
583
|
+
xmlSetGenericErrorFunc( NULL, ruby_xslt_error_handler );
|
584
|
+
xsltSetGenericErrorFunc( NULL, ruby_xslt_error_handler );
|
614
585
|
#endif
|
615
586
|
|
616
587
|
#ifdef USE_EXSLT
|
metadata
CHANGED
@@ -3,12 +3,12 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby-xslt
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.9.
|
6
|
+
version: 0.9.3
|
7
7
|
date: 2005-11-17 00:00:00 +01:00
|
8
8
|
summary: A Ruby class for processing XSLT
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
|
-
email:
|
11
|
+
email: gregoire.lejeune@free.fr
|
12
12
|
homepage: http://raa.ruby-lang.org/project/ruby-xslt/
|
13
13
|
rubyforge_project:
|
14
14
|
description: Ruby/XSLT is a simple XSLT class based on libxml <http://xmlsoft.org/> and libxslt <http://xmlsoft.org/XSLT/>
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- ./extconf.rb
|
38
38
|
- ./extfunc.c
|
39
39
|
- ./extfunc.h
|
40
|
+
- ./lib
|
40
41
|
- ./parameters.c
|
41
42
|
- ./parameters.h
|
42
43
|
- ./parser.c
|
@@ -44,10 +45,10 @@ files:
|
|
44
45
|
- ./rb_utils.c
|
45
46
|
- ./rb_utils.h
|
46
47
|
- ./README
|
48
|
+
- ./ruby-xslt.gemspec
|
47
49
|
- ./tests
|
48
|
-
- ./xslt.c
|
49
50
|
- ./xslt.h
|
50
|
-
- ./
|
51
|
+
- ./xslt_lib.c
|
51
52
|
- debug/memwatch.c
|
52
53
|
- debug/memwatch.h
|
53
54
|
- examples/commentary.dtd
|