require "xml/xslt_lib" module XML class XSLT @@extFunctions = {} # sets up a block for callback when the XPath function # namespace:name( ... ) is encountered in a stylesheet. # # XML::XSLT.registerExtFunc(namespace_uri, name) do |*args| # puts args.inspect # end # # XPath arguments are converted to Ruby objects accordingly: # # number (eg. 1):: Float # boolean (eg. false()):: TrueClass/FalseClass # nodeset (eg. /entry/*):: Array of REXML::Elements # variable (eg. $var):: UNIMPLEMENTED # # It works the same in the other direction, eg. if the block # returns an array of REXML::Elements the value of the function # will be a nodeset. # # Note: currently, passing a nodeset to Ruby or REXML::Elements to # libxslt serializes the nodes and then parses them. Doing this # with large sets is a bad idea. In the future they'll be passed # back and forth using Ruby's libxml2 bindings. def self.registerExtFunc(namespace, name, &block) @@extFunctions[namespace] ||= {} @@extFunctions[namespace][name] = block XML::XSLT.registerFunction(namespace, name) end # deprecated, see +registerExtFunc+ def self.extFunction(name, ns_uri, receiver) #:nodoc: self.registerExtFunc(ns_uri, name) do |*args| receiver.send(name.gsub(/-/, "_"), *args) end end # registers a block to be called when libxml2 or libxslt encounter an error # eg: # # XML::XSLT.registerErrorHandler do |error_str| # $stderr.puts error_str # end # def self.registerErrorHandler(&block) @@error_handler = block end # set up default error handler self.registerErrorHandler do |error_str| $stderr.puts error_str end alias :media_type :mediaType class <