Module: LibXSLT::XSLT
- Defined in:
- ext/libxslt/libxslt.c
Constant Summary collapse
- MAX_DEPTH =
INT2NUM(xsltMaxDepth)
- MAX_SORT =
INT2NUM(XSLT_MAX_SORT)
- ENGINE_VERSION =
rb_str_new2(xsltEngineVersion)
- LIBXSLT_VERSION =
INT2NUM(xsltLibxsltVersion)
- LIBXML_VERSION =
INT2NUM(xsltLibxmlVersion)
- XSLT_NAMESPACE =
rb_str_new2((const char*)XSLT_NAMESPACE)
- DEFAULT_VENDOR =
rb_str_new2(XSLT_DEFAULT_VENDOR)
- DEFAULT_VERSION =
rb_str_new2(XSLT_DEFAULT_VERSION)
- DEFAULT_URL =
rb_str_new2(XSLT_DEFAULT_URL)
- NAMESPACE_LIBXSLT =
rb_str_new2((const char*)XSLT_LIBXSLT_NAMESPACE)
- NAMESPACE_SAXON =
rb_str_new2((const char*)XSLT_SAXON_NAMESPACE)
- NAMESPACE_XT =
rb_str_new2((const char*)XSLT_XT_NAMESPACE)
- NAMESPACE_XALAN =
rb_str_new2((const char*)XSLT_XALAN_NAMESPACE)
Class Method Summary collapse
-
.register_module_function(namespace, name) { ... } ⇒ Proc?
Registers
nameas extension module function innamespacewith the block as callback. -
.registered_module_function?(namespace, name) ⇒ Boolean
Returns
trueifnameis currently registered as extension module function innamespace, orfalseotherwise. -
.unregister_module_function(namespace, name) ⇒ Proc?
Unregisters
nameas extension module function innamespace.
Class Method Details
.register_module_function(namespace, name) { ... } ⇒ Proc?
Registers name as extension module function in namespace with the block as callback. Returns the callback if successful, or nil otherwise.
The callback will be called with whatever XPath expression you pass into the function converted to a Ruby object. Its return value will be converted to an XPath expression again.
Example:
# register your extension function
XSLT.register_module_function('http://ex.ns', 'ex-func') { |xp|
xp.to_a.join('|').upcase
}
# then use it in your stylesheet
<xsl:stylesheet ... xmlns:ex="http://ex.ns">
...
<xsl:value-of select="ex:ex-func(.)" />
<!-- the current node as upper case string -->
</xsl:stylesheet>
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'ext/libxslt/ruby_exslt.c', line 79 static VALUE ruby_xslt_register_module_function(VALUE class, VALUE namespace, VALUE name) { VALUE callback; if (!rb_block_given_p()) { rb_raise(rb_eArgError, "no block given"); } if (xsltRegisterExtModuleFunction( BAD_CAST StringValuePtr(name), BAD_CAST StringValuePtr(namespace), ruby_xslt_module_function_callback ) != 0) { return Qnil; } callback = rb_block_proc(); rb_hash_aset(ruby_xslt_module_function_hash(namespace), name, callback); return callback; } |
.registered_module_function?(namespace, name) ⇒ Boolean
Returns true if name is currently registered as extension module function in namespace, or false otherwise.
134 135 136 137 |
# File 'ext/libxslt/ruby_exslt.c', line 134 static VALUE ruby_xslt_registered_module_function_p(VALUE class, VALUE namespace, VALUE name) { return RTEST(rb_hash_aref(ruby_xslt_module_function_hash(namespace), name)); } |
.unregister_module_function(namespace, name) ⇒ Proc?
Unregisters name as extension module function in namespace. Returns the previous callback if successful, or nil otherwise.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'ext/libxslt/ruby_exslt.c', line 107 static VALUE ruby_xslt_unregister_module_function(VALUE class, VALUE namespace, VALUE name) { VALUE func_hash, callback; func_hash = ruby_xslt_module_function_hash(namespace); if ((callback = rb_hash_aref(func_hash, name)) == Qnil) { return Qnil; } if (xsltUnregisterExtModuleFunction( BAD_CAST StringValuePtr(name), BAD_CAST StringValuePtr(namespace) ) != 0) { return Qnil; } rb_hash_aset(func_hash, name, Qnil); return callback; } |