Note that there are some explanatory texts on larger screens.

plurals
  1. POnokogiri: xml to html
    primarykey
    data
    text
    <p>I just want to do some straight conversion (almost just search and replace) but I'm having trouble just getting things to sit in place - I'm ending up with links out of place and duplicated content. I'm sure I'm doing something silly with my attempts at traversing the xml : )</p> <p>I'm trying with:</p> <pre><code>builder = Nokogiri::HTML::Builder.new do |doc| doc.html { doc.body { doc.div.wrapper! { doc.h1 "Short" xm.css('paragraph').each do |para| doc.h3.para(:id =&gt; para['number']) { doc.text para['number'] } doc.p.narrativeparagraph { xm.css('paragraph inner-section').each do |section| doc.span.innersection { doc.text section.content xm.css('inner-section xref').each do |xref| doc.a(:href =&gt; "#" + xref['number']) { doc.text xref['number'] } end xm.css('paragraph inner-text').each do |innertext| doc.span.innertext { doc.text innertext.content } end } end #inner-section } end#end paragraph }#end wrapper }#end body }#end html end#end builder </code></pre> <p>on:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;looseleaf&gt; &lt;paragraph number="1"&gt; &lt;inner-section&gt; blah one blah &lt;xref number="link1location"&gt;&lt;/xref&gt; &lt;inner-text&gt; blah two blah blah &lt;/inner-text&gt; blah three &lt;/inner-section&gt; &lt;/paragraph&gt; &lt;paragraph number="2"&gt; &lt;inner-section&gt; blah four blah &lt;xref number="link2location"&gt;&lt;/xref&gt; &lt;inner-text&gt;blah five blah blah &lt;/inner-text&gt; blah six &lt;/inner-section&gt; &lt;/paragraph&gt; &lt;/looseleaf&gt; </code></pre> <p>to create:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC- html40/loose.dtd"&gt; &lt;html&gt; &lt;body&gt; &lt;div id="wrapper"&gt; &lt;h1&gt;Short&lt;/h1&gt; &lt;h3 class="para" id="1"&gt;1&lt;/h3&gt; &lt;p class="narrativeparagraph"&gt; &lt;span class="innersection"&gt; blah one blah &lt;a href="#link1location"&gt;link1location&lt;/a&gt; &lt;span class="innertext"&gt; blah two blah blah &lt;/span&gt; blah three&lt;/span&gt; &lt;/p&gt; &lt;h3 class="para" id="2"&gt;2&lt;/h3&gt; &lt;p class="narrativeparagraph"&gt; &lt;span class="innersection"&gt; blah four blah &lt;a ref="#link2location"&gt;link2location&lt;/a&gt; &lt;span class="innertext"&gt;blah five blah blah &lt;/span&gt; blah six&lt;/span&gt;&lt;/p&gt; </code></pre> <p> </p> <p>I've been trying all sorts of things to try to get this to work, the basic html structure comes out okay, but the children of the paragraphs are a mess - any help would be very much appreciated. Regards, Ritchie</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload