libxsl-ruby 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. data/CHANGELOG +14 -0
  2. data/LICENSE +21 -0
  3. data/README +50 -0
  4. data/Rakefile +245 -0
  5. data/TODO +32 -0
  6. data/ext/xml/extconf.rb +97 -0
  7. data/ext/xml/libxml-ruby/libxml.h +92 -0
  8. data/ext/xml/libxml-ruby/ruby_xml_attr.h +31 -0
  9. data/ext/xml/libxml-ruby/ruby_xml_attribute.h +31 -0
  10. data/ext/xml/libxml-ruby/ruby_xml_document.h +37 -0
  11. data/ext/xml/libxml-ruby/ruby_xml_dtd.h +27 -0
  12. data/ext/xml/libxml-ruby/ruby_xml_input_cbg.h +31 -0
  13. data/ext/xml/libxml-ruby/ruby_xml_node.h +38 -0
  14. data/ext/xml/libxml-ruby/ruby_xml_node_set.h +36 -0
  15. data/ext/xml/libxml-ruby/ruby_xml_ns.h +31 -0
  16. data/ext/xml/libxml-ruby/ruby_xml_parser.h +41 -0
  17. data/ext/xml/libxml-ruby/ruby_xml_parser_context.h +32 -0
  18. data/ext/xml/libxml-ruby/ruby_xml_sax_parser.h +31 -0
  19. data/ext/xml/libxml-ruby/ruby_xml_schema.h +26 -0
  20. data/ext/xml/libxml-ruby/ruby_xml_tree.h +22 -0
  21. data/ext/xml/libxml-ruby/ruby_xml_xinclude.h +23 -0
  22. data/ext/xml/libxml-ruby/ruby_xml_xpath.h +34 -0
  23. data/ext/xml/libxml-ruby/ruby_xml_xpath_context.h +34 -0
  24. data/ext/xml/libxml-ruby/ruby_xml_xpointer.h +37 -0
  25. data/ext/xml/libxml-ruby/ruby_xml_xpointer_context.h +28 -0
  26. data/ext/xml/libxslt.c +247 -0
  27. data/ext/xml/libxslt.h +52 -0
  28. data/ext/xml/ruby_xslt_stylesheet.c +298 -0
  29. data/ext/xml/ruby_xslt_stylesheet.h +21 -0
  30. data/ext/xml/ruby_xslt_transform_context.c +63 -0
  31. data/ext/xml/ruby_xslt_transform_context.h +22 -0
  32. data/tests/commentary.dtd +34 -0
  33. data/tests/fuzface.rb +15 -0
  34. data/tests/fuzface.xml +154 -0
  35. data/tests/fuzface.xsl +4 -0
  36. data/tests/ramblings.xsl +46 -0
  37. data/tests/tc_libxslt.rb +65 -0
  38. data/tests/tc_xslt_stylesheet.rb +41 -0
  39. data/tests/tc_xslt_stylesheet2.rb +41 -0
  40. metadata +101 -0
@@ -0,0 +1,26 @@
1
+ /* DO NOT EDIT THIS FILE - UPDATE FROM LIBXML-RUBY ONLY */
2
+ /* Generated: Thu Mar 09 23:18:22 GMT 2006 */
3
+ /* Release : 0.3.6 */
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ #ifndef __RUBY_XML_SCHEMA__
12
+ #define __RUBY_XML_SCHEMA__
13
+
14
+ #include <libxml/schemasInternals.h>
15
+ #include <libxml/xmlschemas.h>
16
+
17
+ extern VALUE cXMLSchema;
18
+
19
+ typedef struct rxp_schema {
20
+ xmlSchemaPtr schema; /* Schema interface */
21
+ } ruby_xml_schema;
22
+
23
+ void ruby_init_xml_schema(void);
24
+ void ruby_schema_free(ruby_xml_schema *rxs);
25
+ #endif
26
+
@@ -0,0 +1,22 @@
1
+ /* DO NOT EDIT THIS FILE - UPDATE FROM LIBXML-RUBY ONLY */
2
+ /* Generated: Thu Mar 09 23:18:22 GMT 2006 */
3
+ /* Release : 0.3.6 */
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ /* $Id: ruby_xml_tree.h,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
12
+
13
+ /* Please see the LICENSE file for copyright and distribution information */
14
+
15
+ #ifndef __RUBY_XML_TREE__
16
+ #define __RUBY_XML_TREE__
17
+
18
+ extern VALUE cXMLTree;
19
+
20
+ void ruby_init_xml_tree(void);
21
+
22
+ #endif
@@ -0,0 +1,23 @@
1
+ /* DO NOT EDIT THIS FILE - UPDATE FROM LIBXML-RUBY ONLY */
2
+ /* Generated: Thu Mar 09 23:18:22 GMT 2006 */
3
+ /* Release : 0.3.6 */
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ /* $Id: ruby_xml_xinclude.h,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
12
+
13
+ /* Please see the LICENSE file for copyright and distribution information */
14
+
15
+ #ifndef __RUBY_XML_XINCLUDE__
16
+ #define __RUBY_XML_XINCLUDE__
17
+
18
+ extern VALUE cXMLXInclude;
19
+ extern VALUE eXMLXIncludeError;
20
+
21
+ void ruby_init_xml_xinclude(void);
22
+
23
+ #endif
@@ -0,0 +1,34 @@
1
+ /* DO NOT EDIT THIS FILE - UPDATE FROM LIBXML-RUBY ONLY */
2
+ /* Generated: Thu Mar 09 23:18:22 GMT 2006 */
3
+ /* Release : 0.3.6 */
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ /* $Id: ruby_xml_xpath.h,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
12
+
13
+ /* Please see the LICENSE file for copyright and distribution information */
14
+
15
+ #ifndef __RUBY_XML_XPATH__
16
+ #define __RUBY_XML_XPATH__
17
+
18
+ extern VALUE cXMLXPath;
19
+ extern VALUE eXMLXPathInvalidPath;
20
+
21
+ typedef struct ruby_xml_xpath {
22
+ VALUE xd;
23
+ VALUE ctxt;
24
+ xmlXPathObjectPtr xpop;
25
+ } ruby_xml_xpath;
26
+
27
+ void ruby_xml_xpath_free(ruby_xml_xpath *rxxp);
28
+ VALUE ruby_xml_xpath_find(int argc, VALUE *argv, VALUE class);
29
+ VALUE ruby_xml_xpath_find2(int argc, VALUE *argv);
30
+ VALUE ruby_xml_xpath_new(VALUE class, VALUE xd, VALUE xxpc,
31
+ xmlXPathObjectPtr xpop);
32
+ void ruby_init_xml_xpath(void);
33
+
34
+ #endif
@@ -0,0 +1,34 @@
1
+ /* DO NOT EDIT THIS FILE - UPDATE FROM LIBXML-RUBY ONLY */
2
+ /* Generated: Thu Mar 09 23:18:22 GMT 2006 */
3
+ /* Release : 0.3.6 */
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ /* $Id: ruby_xml_xpath_context.h,v 1.2 2006/02/27 12:55:32 roscopeco Exp $ */
12
+
13
+ /* Please see the LICENSE file for copyright and distribution information */
14
+
15
+ #ifndef __RUBY_XML_XPATH_CONTEXT__
16
+ #define __RUBY_XML_XPATH_CONTEXT__
17
+
18
+ extern VALUE cXMLXPathContext;
19
+
20
+ typedef struct ruby_xml_xpath_context {
21
+ VALUE xd;
22
+ xmlXPathContextPtr ctxt;
23
+ } ruby_xml_xpath_context;
24
+
25
+ void ruby_xml_xpath_context_free(ruby_xml_xpath_context *rxxpc);
26
+ VALUE ruby_xml_xpath_context_new(VALUE class, VALUE xd,
27
+ xmlXPathContextPtr ctxt);
28
+ VALUE ruby_xml_xpath_context_new2(VALUE xd, xmlXPathContextPtr ctxt);
29
+ VALUE ruby_xml_xpath_context_new3(VALUE xd);
30
+ VALUE ruby_xml_xpath_context_new4(VALUE rnode);
31
+ VALUE ruby_xml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri);
32
+ void ruby_init_xml_xpath_context(void);
33
+
34
+ #endif
@@ -0,0 +1,37 @@
1
+ /* DO NOT EDIT THIS FILE - UPDATE FROM LIBXML-RUBY ONLY */
2
+ /* Generated: Thu Mar 09 23:18:22 GMT 2006 */
3
+ /* Release : 0.3.6 */
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ /* $Id: ruby_xml_xpointer.h,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
12
+
13
+ /* Please see the LICENSE file for copyright and distribution information */
14
+
15
+ #ifndef __RUBY_XML_XPOINTER__
16
+ #define __RUBY_XML_XPOINTER__
17
+
18
+ extern VALUE cXMLXPointer;
19
+ extern VALUE eXMLXPointerInvalidExpression;
20
+
21
+ typedef struct ruby_xml_xpointer {
22
+ VALUE xd;
23
+ VALUE ctxt;
24
+ /*
25
+ * This needs to go into a xpointer data struct:
26
+ *
27
+ * xmlLocationSetPtr xptr;
28
+ *
29
+ * I also need an xpointer data struct type.
30
+ */
31
+ } ruby_xml_xpointer;
32
+
33
+ VALUE ruby_xml_xpointer_point(VALUE class, VALUE node, VALUE xptr_string);
34
+ VALUE ruby_xml_xpointer_point2(VALUE node, VALUE xptr_string);
35
+ void ruby_init_xml_xpointer(void);
36
+
37
+ #endif
@@ -0,0 +1,28 @@
1
+ /* DO NOT EDIT THIS FILE - UPDATE FROM LIBXML-RUBY ONLY */
2
+ /* Generated: Thu Mar 09 23:18:22 GMT 2006 */
3
+ /* Release : 0.3.6 */
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ /* $Id: ruby_xml_xpointer_context.h,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
12
+
13
+ /* Please see the LICENSE file for copyright and distribution information */
14
+
15
+ #ifndef __RUBY_XML_XPOINTER_CONTEXT__
16
+ #define __RUBY_XML_XPOINTER_CONTEXT__
17
+
18
+ extern VALUE cXMLXPointerContext;
19
+ extern VALUE eXMLXPointerContextInvalidPath;
20
+
21
+ typedef struct ruby_xml_xpointer_context {
22
+ VALUE xd;
23
+ xmlXPathContextPtr ctxt;
24
+ } ruby_xml_xpointer_context;
25
+
26
+ void ruby_init_xml_xpointer_context(void);
27
+
28
+ #endif
@@ -0,0 +1,247 @@
1
+ /* $Id: libxslt.c,v 1.1 2006/03/24 10:54:55 roscopeco Exp $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "libxslt.h"
6
+ #include "libxml/xmlversion.h"
7
+
8
+ VALUE cXSLT;
9
+ VALUE eXMLXSLTStylesheetRequireParsedDoc;
10
+
11
+ /* call-seq:
12
+ * xslt.doc => #&lt;XML::Document...&gt;
13
+ *
14
+ * Obtain the source XML::Document.
15
+ */
16
+ VALUE
17
+ ruby_xslt_doc_get(VALUE self) {
18
+ ruby_xslt *rxslt;
19
+ Data_Get_Struct(self, ruby_xslt, rxslt);
20
+ return(rxslt->xml_doc_obj);
21
+ }
22
+
23
+ /* call-seq:
24
+ * xslt.doc = some_xml_document
25
+ *
26
+ * Set the source XML::Document.
27
+ */
28
+ VALUE
29
+ ruby_xslt_doc_set(VALUE self, VALUE xml_doc_obj) {
30
+ ruby_xslt *rxslt;
31
+ ruby_xml_document *rxd;
32
+ ruby_xslt_transform_context *rxtc;
33
+
34
+ if (rb_obj_is_kind_of(xml_doc_obj, cXMLDocument) == Qfalse)
35
+ rb_raise(rb_eTypeError, "Invalid argument: must be of type XML::Document");
36
+
37
+ Data_Get_Struct(self, ruby_xslt, rxslt);
38
+ rxslt->xml_doc_obj = xml_doc_obj;
39
+
40
+ Data_Get_Struct(xml_doc_obj, ruby_xml_document, rxd);
41
+ if (rxd->doc == NULL)
42
+ return(Qnil);
43
+
44
+ rxslt->ctxt = ruby_xslt_transform_context_new3(self);
45
+ Data_Get_Struct(rxslt->ctxt, ruby_xslt_transform_context, rxtc);
46
+
47
+ if (rxslt->xsp == NULL || rxd->doc == NULL)
48
+ return(Qnil);
49
+
50
+ rxtc->ctxt = xsltNewTransformContext(rxslt->xsp, rxd->doc) ;
51
+
52
+ return(rxslt->xml_doc_obj);
53
+ }
54
+
55
+ /* call-seq:
56
+ * xslt.filename => "filename.xsl"
57
+ *
58
+ * Obtain the stylesheet filename.
59
+ */
60
+ VALUE
61
+ ruby_xslt_filename_get(VALUE self) {
62
+ ruby_xslt *rxslt;
63
+ Data_Get_Struct(self, ruby_xslt, rxslt);
64
+
65
+ if (rxslt->data_type != RUBY_LIBXSLT_SRC_TYPE_FILE)
66
+ return(Qnil);
67
+ else
68
+ return((VALUE)rxslt->data);
69
+ }
70
+
71
+
72
+ /* call-seq:
73
+ * xslt.filename = "filename.xsl"
74
+ *
75
+ * Set the stylesheet filename.
76
+ */
77
+ VALUE
78
+ ruby_xslt_filename_set(VALUE self, VALUE filename) {
79
+ ruby_xslt *rxslt;
80
+ Check_Type(filename, T_STRING);
81
+ Data_Get_Struct(self, ruby_xslt, rxslt);
82
+
83
+ if (rxslt->data_type != RUBY_LIBXSLT_SRC_TYPE_NULL)
84
+ return(Qnil);
85
+
86
+ rxslt->data_type = RUBY_LIBXSLT_SRC_TYPE_FILE;
87
+ rxslt->data = (void *)filename;
88
+ return(filename);
89
+ }
90
+
91
+
92
+ void
93
+ ruby_xslt_free(ruby_xslt *rxslt) {
94
+ if (rxslt != NULL)
95
+ free(rxslt);
96
+ }
97
+
98
+
99
+ void
100
+ ruby_xslt_mark(ruby_xslt *rxslt) {
101
+ if (rxslt == NULL) return;
102
+ if (!NIL_P(rxslt->ctxt)) rb_gc_mark(rxslt->ctxt);
103
+ if (!NIL_P(rxslt->str)) rb_gc_mark(rxslt->str);
104
+ if (!NIL_P(rxslt->xml_doc_obj)) rb_gc_mark(rxslt->xml_doc_obj);
105
+
106
+ switch(rxslt->data_type) {
107
+ case RUBY_LIBXSLT_SRC_TYPE_FILE:
108
+ if (rxslt->data != NULL)
109
+ rb_gc_mark((VALUE)rxslt->data);
110
+ break;
111
+ }
112
+ }
113
+
114
+
115
+ /* call-seq:
116
+ * XML::XSLT.new => #&lt;XML::XSLT...&gt;
117
+ *
118
+ * Create a new XSLT instance. You will need to specify
119
+ * a filename and document for the instance after it is
120
+ * created.
121
+ */
122
+ VALUE
123
+ ruby_xslt_new(VALUE class) {
124
+ ruby_xslt *rxslt;
125
+
126
+ rxslt = (ruby_xslt *)malloc(sizeof(ruby_xslt));
127
+ if (rxslt == NULL)
128
+ rb_raise(rb_eNoMemError, "No memory left for XSLT struct");
129
+
130
+ rxslt->ctxt = Qnil;
131
+ rxslt->data = NULL;
132
+ rxslt->data_type = RUBY_LIBXSLT_SRC_TYPE_NULL;
133
+ rxslt->str = Qnil;
134
+ rxslt->xml_doc_obj = Qnil;
135
+ rxslt->xsp = NULL;
136
+
137
+ return(Data_Wrap_Struct(class, ruby_xslt_mark, ruby_xslt_free, rxslt));
138
+ }
139
+
140
+ /* call-seq:
141
+ * XML::XSLT.file("filename.xsl") => #&lt;XML::XSLT...&gt;
142
+ *
143
+ * Create a new XSLT instance with the supplied stylesheet filename.
144
+ */
145
+ VALUE
146
+ ruby_xslt_new_file(VALUE class, VALUE filename) {
147
+ VALUE xslt;
148
+
149
+ xslt = ruby_xslt_new(class);
150
+ ruby_xslt_filename_set(xslt, filename);
151
+ return(xslt);
152
+ }
153
+
154
+ /* call-seq:
155
+ * xslt.parse => #&lt;XML::XSLT::Stylesheet...&gt;
156
+ *
157
+ * Parse the xsl source (specified by +filename+) and create
158
+ * a +Stylesheet+ instance that will apply it against the
159
+ * source document. If a parsed XML::Document isn't associated
160
+ * with this +XSLT+ instance (via #doc=) then a
161
+ * Stylesheet::RequireParsedDoc exception is raised.
162
+ */
163
+ VALUE
164
+ ruby_xslt_parse(VALUE self) {
165
+ ruby_xml_document *rxd;
166
+ ruby_xslt *rxslt;
167
+ ruby_xslt_stylesheet *xss;
168
+ VALUE xssobj;
169
+ xsltStylesheetPtr sheet;
170
+
171
+ Data_Get_Struct(self, ruby_xslt, rxslt);
172
+
173
+ if (rxslt->data_type == RUBY_LIBXSLT_SRC_TYPE_FILE) {
174
+ /*xssobj = ruby_xslt_stylesheet_new(cXSLTStylesheet,
175
+ xsltParseStylesheetFile((const xmlChar *)
176
+ STR2CSTR(rxslt->data)));*/
177
+ sheet = xsltParseStylesheetFile((const xmlChar *) STR2CSTR(rxslt->data));
178
+
179
+ if (sheet) {
180
+ xssobj = ruby_xslt_stylesheet_new(cXSLTStylesheet, sheet);
181
+ Data_Get_Struct(xssobj, ruby_xslt_stylesheet, xss);
182
+ xss->data = (void *)rb_obj_dup((VALUE)rxslt->data);
183
+ xss->xml_doc_obj = rxslt->xml_doc_obj;
184
+ } else
185
+ xssobj = Qnil;
186
+
187
+ } else if (rxslt->xml_doc_obj != Qnil) {
188
+ Data_Get_Struct(rxslt->xml_doc_obj, ruby_xml_document, rxd);
189
+ /*xssobj = ruby_xslt_stylesheet_new(cXSLTStylesheet,
190
+ xsltParseStylesheetDoc(rxd->doc));*/
191
+ sheet = xsltParseStylesheetDoc(rxd->doc);
192
+ if (sheet) {
193
+ xssobj = ruby_xslt_stylesheet_new(cXSLTStylesheet,sheet);
194
+ Data_Get_Struct(xssobj, ruby_xslt_stylesheet, xss);
195
+ xss->xml_doc_obj = rxslt->xml_doc_obj;
196
+ } else
197
+ xssobj = Qnil;
198
+
199
+ } else {
200
+ xssobj = Qnil;
201
+ }
202
+
203
+ return(xssobj);
204
+ }
205
+
206
+ #ifdef RDOC_NEVER_DEFINED
207
+ mXML = rb_define_module("XML");
208
+ #endif
209
+
210
+ void
211
+ Init_libxslt(void) {
212
+ LIBXML_TEST_VERSION;
213
+ mXML = rb_const_get(rb_cObject, rb_intern("XML"));
214
+ cXMLDocument = rb_const_get(mXML, rb_intern("Document"));
215
+
216
+ cXSLT = rb_define_class_under(mXML, "XSLT", rb_cObject);
217
+
218
+ rb_define_const(cXSLT, "MAX_DEPTH", INT2NUM(xsltMaxDepth));
219
+ rb_define_const(cXSLT, "MAX_SORT", INT2NUM(XSLT_MAX_SORT));
220
+ rb_define_const(cXSLT, "ENGINE_VERSION", rb_str_new2(xsltEngineVersion));
221
+ rb_define_const(cXSLT, "LIBXSLT_VERSION", INT2NUM(xsltLibxsltVersion));
222
+ rb_define_const(cXSLT, "LIBXML_VERSION", INT2NUM(xsltLibxmlVersion));
223
+ rb_define_const(cXSLT, "XSLT_NAMESPACE", rb_str_new2((const char*)XSLT_NAMESPACE));
224
+ rb_define_const(cXSLT, "DEFAULT_VENDOR", rb_str_new2(XSLT_DEFAULT_VENDOR));
225
+ rb_define_const(cXSLT, "DEFAULT_VERSION", rb_str_new2(XSLT_DEFAULT_VERSION));
226
+ rb_define_const(cXSLT, "DEFAULT_URL", rb_str_new2(XSLT_DEFAULT_URL));
227
+ rb_define_const(cXSLT, "NAMESPACE_LIBXSLT", rb_str_new2((const char*)XSLT_LIBXSLT_NAMESPACE));
228
+ rb_define_const(cXSLT, "NAMESPACE_NORM_SAXON", rb_str_new2((const char*)XSLT_NORM_SAXON_NAMESPACE));
229
+ rb_define_const(cXSLT, "NAMESPACE_SAXON", rb_str_new2((const char*)XSLT_SAXON_NAMESPACE));
230
+ rb_define_const(cXSLT, "NAMESPACE_XT", rb_str_new2((const char*)XSLT_XT_NAMESPACE));
231
+ rb_define_const(cXSLT, "NAMESPACE_XALAN", rb_str_new2((const char*)XSLT_XALAN_NAMESPACE));
232
+
233
+ ruby_init_xslt_stylesheet();
234
+ ruby_init_xslt_transform_context();
235
+
236
+
237
+ rb_define_singleton_method(cXSLT, "file", ruby_xslt_new_file, 1);
238
+ rb_define_singleton_method(cXSLT, "new", ruby_xslt_new, 0);
239
+
240
+ rb_define_method(cXSLT, "doc", ruby_xslt_doc_get, 0);
241
+ rb_define_method(cXSLT, "doc=", ruby_xslt_doc_set, 1);
242
+ rb_define_method(cXSLT, "filename", ruby_xslt_filename_get, 0);
243
+ rb_define_method(cXSLT, "filename=", ruby_xslt_filename_set, 1);
244
+ rb_define_method(cXSLT, "parse", ruby_xslt_parse, 0);
245
+
246
+ exsltRegisterAll();
247
+ }