module Nokogiri::XSLT

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

Public Class Methods

parse(string, modules = {}) click to toggle source

Parse the stylesheet in string, register any modules

# 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) → Array click to toggle source

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

# File lib/nokogiri/xslt.rb, line 49
def quote_params(params)
  params.flatten.each_slice(2).each_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