Class: PolyrexXSLT
- Inherits:
-
Object
- Object
- PolyrexXSLT
- Defined in:
- lib/polyrex-xslt.rb
Instance Method Summary collapse
-
#initialize(schema: '', xslt_schema: '', debug: false) ⇒ PolyrexXSLT
constructor
A new instance of PolyrexXSLT.
- #to_xslt ⇒ Object
Constructor Details
#initialize(schema: '', xslt_schema: '', debug: false) ⇒ PolyrexXSLT
Returns a new instance of PolyrexXSLT.
11 12 13 14 15 |
# File 'lib/polyrex-xslt.rb', line 11 def initialize(schema: '', xslt_schema: '', debug: false) @schema, @xslt_schema, @debug = schema, xslt_schema, debug end |
Instance Method Details
#to_xslt ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/polyrex-xslt.rb', line 17 def to_xslt() a_element = @schema.split('/').map{|x| x[/\w+/]} @xslt_schema = build_xslt_schema(@schema) if @xslt_schema.empty? puts ('@xslt_schema: ' + @xslt_schema.inspect).debug if @debug a_html = @xslt_schema.split('/').map do |x| result = x.match(/([\w\>]+)(?:[\(\[]([^\]\)]+)[\]\)])?(.*)/) name, children, remaining = result.captures if result list = children.split(/ *, */).map {|y| y.split(':',2)} if children [name, list] end puts ('a_html: ' + a_html.inspect).debug if @debug a = a_element.zip(a_html) xml = RexleBuilder.new raw_a = xml.xsl_stylesheet(xmlns_xsl: \ "http://www.w3.org/1999/XSL/Transform", version: "1.0") do xml.xsl_output(method: "xml", indent: "yes", \ :"omit-xml-declaration" => "yes") a.each_cons(2).with_index do |x,i| x1, x2 = x puts 'x1: ' + x1.inspect if @debug build(xml, x1, x2) build(xml, x2) if x2 end end xml2 = Rexle.new(raw_a).xml(pretty: true).gsub('xsl_apply_templates',\ 'xsl:apply-templates').gsub('xsl_value_of','xsl:value-of').\ gsub('xsl_template','xsl:template').gsub('xsl_','xsl:').\ gsub('xmlns_xsl','xmlns:xsl') end |