How do I delete all but the first-child of a node?

66 views
Skip to first unread message

Joseph Smith

unread,
May 9, 2013, 12:04:13 PM5/9/13
to enf...@googlegroups.com
Hello-- I have a recurring situation where I want to keep the first item in an unordered list (to clone-for with) and delete the rest (which merely serve as sample data in my template). 

e.g., If I have this: 
<ul>
<li>thing</li>
<li>thing2</li>
<li>thing3></li>
</ul>

I want:
<ul>
<li>thing</li>
</ul> 

My snippet will do something like this: 

(defsnippet mysnippet "path/to/template.html" ["#container"]
  [things]
  [(enfocus.enlive.syntax/but ":ul > *:first-child)] (remove-node)
  [":ul > *:first-child] (clone-for [thing things] (content thing))

Unfortunately, that doesn't work. enfocus.enlive.syntax/but doesn't seem to select "all, but".

Any help is greatly appreciated. 

Thanks! 

ckirkendall

unread,
May 9, 2013, 1:10:41 PM5/9/13
to enf...@googlegroups.com
Joseph,
Below is how you would do this with string base selectors.  I will have to do a bit more testing on how to do it with enlive syntax.  

(defsnippet mysnippet "path/to/template.html" ["#container"]
  [things]
  ["ul > li:not(:first-child)"] (remove-node)
  ["ul > li:first-of-type"] (clone-for [thing things] (content thing))

CK

Joseph Smith

unread,
May 9, 2013, 3:02:59 PM5/9/13
to enf...@googlegroups.com
Excellent, thanks!
Reply all
Reply to author
Forward
0 new messages