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
-
.parse(string, modules = {}) ⇒ Object
Parse the stylesheet in
string
, register anymodules
. -
.quote_params(params) ⇒ Object
:call-seq: quote_params(params) → Array.
-
.register(uri, custom_handler_class) ⇒ Object
Register a class that implements custom XSLT transformation functions.
Class Method Details
.parse(string, modules = {}) ⇒ Object
Parse the stylesheet in string
, register any modules
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/nokogiri/xslt.rb', line 25 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
:call-seq:
quote_params(params) → Array
Quote parameters in params
for stylesheet safety. See Nokogiri::XSLT::Stylesheet.transform for example usage.
- Parameters
-
params
(Hash, Array) XSLT parameters (key->value, or tuples of [key, value])
- Returns
-
Array of string parameters, with quotes correctly escaped for use with XSLT::Stylesheet.transform
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/nokogiri/xslt.rb', line 49 def quote_params(params) params.flatten.each_slice(2).with_object([]) do |kv, quoted_params| key, value = kv.map(&:to_s) value = if /'/.match?(value) "concat('#{value.gsub(/'/, %q{', "'", '})}')" else "'#{value}'" end quoted_params << key quoted_params << value end end |
.register(uri, custom_handler_class) ⇒ Object
Register a class that implements custom XSLT transformation functions.
339 340 341 342 343 344 345 346 347 348 |
# File 'ext/nokogiri/xslt_stylesheet.c', line 339
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;
}
|