如何在Enlive中使用选择器否定(但…)更复杂的HTML片段?

如何在Enlive中使用选择器否定(但…)更复杂的HTML片段?,第1张

概述我有一个类似于HTML代码段: <div id="root"> <div id="A" attrib_2="bar"></div> <div id="B" attrib_2="baz"> <div id="H" attrib_1="gnu"> <p> <div id="F" attrib_2="baz"></d 我有一个类似于HTML代码段:
<div ID="root">    <div ID="A" attrib_2="bar"></div>    <div ID="B" attrib_2="baz">        <div ID="H" attrib_1="gnu">            <p>                <div ID="F" attrib_2="baz"></div>            </p>        </div>    </div>    <div ID="C" attrib_2="owl"></div>    <div ID="D" attrib_2="uhu"></div>    <div ID="E" attrib_2="boom"></div></div>

现在,我想选择所有具有attrib_2(* [attrb_2])的片段,不包括具有attrib_1集合的节点的下降点.可以有更多的嵌套级别与任意标签(如本例中的< p>).有了Enlive(http://enlive.cgrand.net/),我已经尝试过如下:

(select snippet [(but (attr? :attrib_1)) (attr? :attrib_2)])

但是这不行,因为否定(但是(attr?:attrib_1))也匹配< p>标签.有没有办法用给定的选择器谓词(http://enlive.cgrand.net/syntax.html)表达这一点,还是要写自己的?

提前致谢

-Jochen

解决方法 你必须编写自己的选择器:
(def parents   (zip-pred (fn [loc pred]              (some pred (take-while IDentity (iterate zip/up loc))))))

(另)

接着

(select snippet [[(attr? :attrib_2) (but (parents (attr? :attrib_1))]])

应该工作

总结

以上是内存溢出为你收集整理的如何在Enlive中使用选择器否定(但…)更复杂的HTML片段?全部内容,希望文章能够帮你解决如何在Enlive中使用选择器否定(但…)更复杂的HTML片段?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1103168.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存