module Nokogiri::XSLT
def parse(string, modules = {})
# "\n"
# "
# "
# "
# => "\n" +
xsl.transform(xml).to_xml
xsl = Nokogiri.XSLT(xsl, "http://nokogiri.org/xslt/myfuncs" => handler)
XSL
extension-element-prefixes="myfuncs">
xmlns:myfuncs="http://nokogiri.org/xslt/myfuncs"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
end
end
node.text.reverse
def reverse(node)
handler = Class.new do
XML
xml = Nokogiri.XML(<<~XML)
*Example*
Also see Nokogiri::XSLT.register
⚠ The XSLT handler classes are registered *globally*.
namespace to a custom function handler.
- +modules+ (Hash
- +xsl+ (String) XSL content to be parsed into a stylesheet
[Parameters]
Parse the stylesheet in +xsl+, registering optional +modules+ as custom class handlers.
parse(xsl, modules) → Nokogiri::XSLT::Stylesheet
parse(xsl) → Nokogiri::XSLT::Stylesheet
:call-seq:
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
def quote_params(params)
[Returns] Array of string parameters, with quotes correctly escaped for use with XSLT::Stylesheet.transform
- +params+ (Hash, Array) XSLT parameters (key->value, or tuples of [key, value])
[Parameters]
See Nokogiri::XSLT::Stylesheet.transform for example usage.
Quote parameters in +params+ for stylesheet safety.
quote_params(params) → Array
:call-seq:
def quote_params(params) params.flatten.each_slice(2).with_object([]) do |kv, quoted_params| key, value = kv.map(&:to_s) value = if value.include?("'") "concat('#{value.gsub("'", %q{', "'", '})}')" else "'#{value}'" end quoted_params << key quoted_params << value end end
def register(uri, custom_handler_class)
See Nokogiri::XSLT.parse for usage.
transformation
- +custom_handler_class+ (Class) A class with ruby methods that can be called during
- +uri+ (String) The namespace for the custom handlers
[Parameters}
⚠ The XSLT handler classes are registered *globally*.
Register a class that implements custom XSLT transformation functions.
register(uri, custom_handler_class)
call-seq:
def register(uri, custom_handler_class) # NOTE: this is implemented in the C extension, see ext/nokogiri/xslt_stylesheet.c raise NotImplementedError, "Nokogiri::XSLT.register is not implemented on JRuby" end if Nokogiri.jruby?