module LibXSLT::XSLT

The libxslt gem provides Ruby language bindings for GNOME's Libxslt toolkit. It is free software, released under the MIT License.

Using the bindings is straightforward:

stylesheet_doc = XML::Document.file('stylesheet_file')
stylesheet = XSLT::Stylesheet.new(stylesheet_doc)

xml_doc = XML::Document.file('xml_file')
result = stylesheet.apply(xml_doc)

Constants

DEFAULT_URL
DEFAULT_VENDOR
DEFAULT_VERSION
ENGINE_VERSION
LIBXML_VERSION
LIBXSLT_VERSION
MAX_DEPTH
MAX_SORT
NAMESPACE_LIBXSLT
NAMESPACE_SAXON
NAMESPACE_XALAN
NAMESPACE_XT
XSLT_NAMESPACE

Public Class Methods

register_module_function(namespace, name) { ... } → Proc or nil click to toggle source

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>
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) → true or false click to toggle source

Returns true if name is currently registered as extension module function in namespace, or false otherwise.

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 or nil click to toggle source

Unregisters name as extension module function in namespace. Returns the previous callback if successful, or nil otherwise.

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;
}