Module: Nokogiri::XSLT

Defined in:
lib/nokogiri/xslt.rb,
lib/nokogiri/xslt/stylesheet.rb,
ext/nokogiri/nokogiri.c

Overview

See Nokogiri::XSLT::Stylesheet for creating and manipulating Stylesheet object.

Defined Under Namespace

Classes: Stylesheet

Class Method Summary collapse

Class Method Details

.parse(string, modules = {}) ⇒ Object

Parse the stylesheet in string, register any modules



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/nokogiri/xslt.rb', line 23

def parse(string, modules = {})
  modules.each do |url, klass|
    XSLT.register(url, klass)
  end

  doc = XML::Document.parse(string, nil, nil, XML::ParseOptions::DEFAULT_XSLT)
  if Nokogiri.jruby?
    Stylesheet.parse_stylesheet_doc(doc, string)
  else
    Stylesheet.parse_stylesheet_doc(doc)
  end
end

.quote_params(params) ⇒ Object

Quote parameters in params for stylesheet safety



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/nokogiri/xslt.rb', line 38

def quote_params(params)
  parray = (params.instance_of?(Hash) ? params.to_a.flatten : params).dup
  parray.each_with_index do |v, i|
    parray[i] = if i % 2 > 0
      if v =~ /'/
        "concat('#{v.gsub(/'/, %q{', "'", '})}')"
      else
        "'#{v}'"
      end
    else
      v.to_s
    end
  end
  parray.flatten
end

.register(uri, custom_handler_class) ⇒ Object

Register a class that implements custom XSLT transformation functions.



240
241
242
243
244
245
246
247
248
249
# File 'ext/nokogiri/xslt_stylesheet.c', line 240

static VALUE
registr(VALUE self, VALUE uri, VALUE obj)
{
  VALUE modules = rb_iv_get(self, "@modules");
  if (NIL_P(modules)) { rb_raise(rb_eRuntimeError, "wtf! @modules isn't set"); }

  rb_hash_aset(modules, uri, obj);
  xsltRegisterExtModule((unsigned char *)StringValueCStr(uri), initFunc, shutdownFunc);
  return self;
}