Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I combine results from zip-filter queries on an xml tree in Clojure?
    text
    copied!<p>I want to combine the results of three zip-filter queries on an xml tree. The XML I am parsing looks like this:</p> <pre><code>&lt;someroot&gt; &lt;publication&gt; &lt;contributors&gt; &lt;person_name&gt; &lt;surname&gt;Surname A&lt;/surname&gt; &lt;/person_name&gt; &lt;person_name&gt; &lt;given_name&gt;Given B&lt;/given_name&gt; &lt;surname&gt;Surname B&lt;/surname&gt; &lt;suffix&gt;Suffix B&lt;/suffix&gt; &lt;/person_name&gt; &lt;/contributors&gt; &lt;/publication&gt; &lt;/someroot&gt; </code></pre> <p>From this example you can see that <code>&lt;given_name&gt;</code> and <code>&lt;suffix&gt;</code> are optional - only <code>&lt;surname&gt;</code> is required. Here in lies my problem - if I run three separate queries the responses I get will be out of kilter with each other:</p> <pre><code>(xml-&gt; xml :publication :contributors :person_name :given_name text) (xml-&gt; xml :publication :contributors :person_name :surname text) (xml-&gt; xml :publication :contributors :person_name :suffix text) </code></pre> <p>After running these three queries I will be left with three sequences whose cardinalities do not match; <code>given_name</code> and <code>suffix</code> will be length 1 while <code>surname</code> will be length 2. This makes it impossible for me to combine the components of each name. I need to write a single query that will perform this name concatenation during sequence construction.</p> <p>I'm looking at the very sparse documentation for <code>clojure.contrib.zip-filter.xml</code> and can't figure out how I could do this (or if it is even possible). Unfortunately I am a Clojure (and Lisp) newbie! Can anyone point out how I can write a query that will concatenate three other embedded queries?</p>
 

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