Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure 如何编写Enlive选择器以返回“返回”;“集群”;标签的数量?_Clojure_Enlive - Fatal编程技术网

Clojure 如何编写Enlive选择器以返回“返回”;“集群”;标签的数量?

Clojure 如何编写Enlive选择器以返回“返回”;“集群”;标签的数量?,clojure,enlive,Clojure,Enlive,我正在使用Enlive编写一些Clojure代码来处理一组XML文档。它们是XML格式,大量借用HTML,但添加了一些自定义标记,我的工作是将它们转换为真正的HTML。现在最困扰我的定制标签是,它被用于各种不应该使用的地方。例如,它通常用于制作本应使用和制作的列表。下面是我遇到的一个例子: <p class="Normal">Some text</p> <p class="ListWithTabs">(a)<tab />First list ite

我正在使用Enlive编写一些Clojure代码来处理一组XML文档。它们是XML格式,大量借用HTML,但添加了一些自定义标记,我的工作是将它们转换为真正的HTML。现在最困扰我的定制标签是
,它被用于各种不应该使用的地方。例如,它通常用于制作本应使用
  • 制作的列表。下面是我遇到的一个例子:

    <p class="Normal">Some text</p>
    <p class="ListWithTabs">(a)<tab />First list item</p>
    <p class="ListWithTabs">(b)<tab />Second list item</p>
    <p class="ListWithTabs">(c)<tab />Third list item</p>
    <p class="Normal">Some more text</p>
    <p class="AnotherList">1.<tab />Another list</p>
    <p class="AnotherList">2.<tab />Two items this time</p>
    <p class="Normal">Some final text</p>
    
    我能够创建以下选择器:

    (def first-of-tab-group [(e/has [:tab])
                             (e/left (complement (e/has [:tab])))])
    (def rest-of-tab-group [(e/has [:tab])
                            (e/left (e/has [:tab]))])
    
    但现在我被卡住了。我想做一些类似
    (e/select snippet[[(e/start-at-first-of-tab-group)(e/take-while-of-tab-group)])
    ,但据我所知,Enlive没有任何类似
    start-at
    take-while
    的功能


    感觉我很接近,但只是错过了最后一个关键步骤。那么我该如何走最后一步呢?如何只选择符合特定规则的元素“集群”,而忽略符合相同规则但不属于第一个“集群”的其他元素?

    根据enlive文档:{node selector node selector}我们可以将这些元素分组 {[:p.Normal][:p.Normal]}假设这是分隔符


    现在,我的问题是:如何使用enlive在每个结果组中迭代结果。

    回答我自己的问题。。。大概看起来片段(
    {from selector to selector}
    )就是我想要的。不知道我怎么会错过第一次。如果是的话,你能回答吗?
    [
      [{:tag :p, :content (... "First list item" ...)}
       {:tag :p, :content (... "Second list item" ...)}
       {:tag :p, :content (... "Third list item" ...)}
      ] ; 3 items in first list
      [{:tag :p, :content (... "Another list" ...)}
       {:tag :p, :content (... "With just two items" ...)}
      ] ; 2 items in second list
    ]
    
    (def first-of-tab-group [(e/has [:tab])
                             (e/left (complement (e/has [:tab])))])
    (def rest-of-tab-group [(e/has [:tab])
                            (e/left (e/has [:tab]))])