Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying XML nodes with Nokogiri in Rails view
    primarykey
    data
    text
    <p>So using the advice found in my previous '<a href="https://stackoverflow.com/questions/8017667/using-nokogiri-to-search-through-xml-file-based-on-user-input-in-rails-app">question</a>', I have been able to get the results I want. </p> <p>I was wondering if anyone had an easy way to display these results in a Rails view that also has non XML content.</p> <p>I've looked into XSLT but don't know enough about it, especially not in relation to Rails, to know whether that is where I should spend my time. If so, I'd love some pointers on how I can use XSLT in Rails views.</p> <p>What I am looking for is to display a list of 'sdnEntry' results (see '<a href="http://www.treasury.gov/resource-center/sanctions/SDN-List/Documents/sdn.xsd" rel="nofollow noreferrer">XML Schema</a>' for details.)</p> <p>As you will see from the '<a href="http://www.treasury.gov/resource-center/sanctions/SDN-List/Documents/sdn.xsd" rel="nofollow noreferrer">XML Schema</a>', not all of the 'sdnEntry' items have the same elements. Therefore, I'd like to display the following information about each 'sdnEntry', omitting any empty elements where applicable.</p> <p>Please feel free to ask questions in comments. I really appreciate the help.</p> <p>EDIT #1: The XML file can be found <a href="http://www.treasury.gov/ofac/downloads/sdn.xml" rel="nofollow noreferrer">here</a>. (6MB)</p> <p>EDIT #2: I'd prefer something like a <code>&lt;dl&gt;/&lt;dt&gt;&lt;dd&gt;</code> list. Heck, I'd even settle for a plain old table. As for empty elements, you will see from the schema, that some child elements (like 'firstName' or 'address3', etc.) have 0 minimum occurrences, and are therefore not found for every 'sdnEntry'. If possible, I'd rather not show blank child elements. If that's a problem, I'd be fine with blanks in the end, if needed.</p> <p>EDIT #3: The results will always be a Nokogiri NodeSet of one or more 'sdnEntry' items. That's all I would need to display. I am confident that with enough guidance or example code, I could apply any provided solution to other needs down the line.</p>
    singulars
    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