Using Enlive for sitemaps - multilingual/regional sitemaps having xhtml:link tags

39 views
Skip to first unread message

Kai

unread,
Jul 4, 2014, 5:10:22 PM7/4/14
to enliv...@googlegroups.com
Hi all,

I'm trying to use Enlive to generate a multilingual, multi-regional sitemap following the Google spec/example here: 

...and not having much progress.  Say my template file looks like this,

<?xml version="1.0" encoding="UTF-8"?>
        xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <url>
        <loc>http://www.example.com/english/</loc>
        <xhtml:link
            rel="alternate"
            hreflang="de"
            href="http://www.example.com/deutsch/" />
        <xhtml:link
            rel="alternate"
            hreflang="en"
            href="http://www.example.com/english/" />
    </url>
</urlset>


Now, it looks to me like one deftemplate (for urlset tag) and two snippets (outer loop of url tag, inner loop of xhtml:link tags) should do the job, but exactly what selectors to use, is stumping me.  This code, for example, does not work to produce the expected/desired sitemap:

(require '[net.cgrand.enlive-html :as html])

(html/defsnippet xhtml-link-snippet "sitemap-mlmr.xml"
  [:xhtml:link]
  [hreflang-m]
  [:xhtml:link] (html/set-attr :hreflang (:hreflang hreflang-m)
                               :href (:href hreflang-m)))

(html/defsnippet url-snippet "sitemap-mlmr.xml"
  [:url] 
  [url-m]
  [:loc] (html/content (:loc url-m))
  [[(html/nth-last-child 1)]] (html/content (map xhtml-link-snippet
                                                 (:hreflang-list url-m))))

(html/deftemplate sitemap-mlmr "sitemap-mlmr.xml"
  [url-list]
  [:urlset] (html/content (map url-snippet url-list)))

(def sample-urls
    :hreflang-list [{:hreflang "en" :href "http://example.com/de/en"}
                    {:hreflang "de-de" :href "http://example.com/de/de"}]}
    :hreflang-list [{:hreflang "de-de" :href "http://example.com/de/de"}
                    {:hreflang "en" :href "http://example.com/de/en"}]}
   ])

(reduce str (sitemap-mlmr sample-urls))


The self-closing xhtml:link tag seems to cause issues, but is not the only problem.  Any tips/help appreciated, thanks!

K

Reply all
Reply to author
Forward
0 new messages