Search

I’ve got a data source that imports blog posts from an Atom feed. In the datasource, I added atom as a namespace name and http://www.w3.org/2005/Atom as the URI. I instructed it to include atom:feed/atom:entry elements.

The entries show up fine in the debug panel, but I can’t select them via XPath: http://pastie.org/994162

I can select //blog-posts, and //blog-posts/* will select all of the entry nodes, but //blog-posts/atom:entry and //blog-posts/entry don’t select anything.

On my template, I also added the atom namespace: http://pastie.org/994164

And calling it with <xsl:apply-templates select="blog-posts/atom:entry[position() &lt;= 5]"/> doesn’t do anything.

At first I thought it might be the feed, but the feed validates, and I have the same problem when I try a blank, default Atom feed.

I searched the forum, and several similar topics came up, but so far I’ve tried everything recommended in those and nothing seems to be working.

It’s a bit verbose (but what isn’t in xslt?) but try this for you xpath:

//blog-posts/entry[namespace-uri() = 'http://www.w3.org/2005/Atom']

I seem to recall some oddness where the XPath is not actaully ‘understanding’ the namespace the element is in, but really just matching on the element name, which includes the prefix. This is why you can’t match on a namespaced wildcard like this: //blog-posts/atom:*.

It’s a bit verbose (but what isn’t in xslt?)

Hahaha, too true. Unfortunately, that selector doesn’t work. It did cause me to notice something else, though.

My previous select (blog-posts/atom:entry) did work. However, I forgot to add the atom: namespace to child nodes! So the template was outputting HTML tags, but they were empty because they weren’t getting any of the entry’s content.

XPath is sneaky that way. I spent so much time trying to figure out why it was apparently not working that I didn’t bother examining the template itself… .

The debug panel is also a bit misleading in this case, since it appears its XPath evaluator can’t handle non-default namespaces.

Thanks for the help.

Glad to hear you’ve gotten it working. I don’t know the specifics, but I don’t think namespace support is as strong for client-side xpath as it is in libxslt.

Namespaces can be a little wonky , but they can also be a great tool if you can get them working for you.

Hi,

I have the same problem retreiving tweets using an Atom feed. This is the feed:

http://search.twitter.com/search.atom?geocode=51.436596%2C5.478001%2C25.0km&q=+eindhoven+near%3AEindhoven+within%3A25km

I made a dynamic datasource and created the following namespaces:

  • atom: http://www.w3.org/2005/Atom
  • twitter: http://api.twitter.com/
  • openSearch: http://a9.com/-/spec/opensearch/1.1
  • google: http://base.google.com/ns/1.0

I use the following xPath in my Dynamic datasource:

atom:feed/atom:entry

I also tried the following:

//feed/entry[namespace-uri() = 'http://www.w3.org/2005/Atom']

But this results in a ‘no records found’-error.

Any idea what I am doing wrong? Perhaps it’s also an idea to have a section in the documentation expaining dynamic datasources and the role of namespace declarations in it.

I am using a similar URL (search.twitter.com but a different query) and

/atom:feed/atom:entry[1]

is working just fine for me. What does / give you?

I do see the XML output, and when I use /atom:feed/atom:entry the entry come into my XML datasource, but I can’t xPath through them.

For example, the following XSL-statement would return zero:

<xsl:for-each select="count(tweets/entry)" />

While my XML output is:

<tweets status="fresh" creation="2010-08-27T14:52:54+02:00">
  <entry xmlns:google="http://base.google.com/ns/1.0" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns="http://www.w3.org/2005/Atom" xmlns:twitter="http://api.twitter.com/">
    ...some stuff...
  </entry>
  <entry xmlns:google="http://base.google.com/ns/1.0" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns="http://www.w3.org/2005/Atom" xmlns:twitter="http://api.twitter.com/">
    ...also some stuff...
  </entry>

  ...etc...

</tweets>

Why doesn’t my xPath work?

Did you add the namespaces to your stylesheet element like so?

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:atom="http://www.w3.org/2005/Atom"
    exclude-result-prefixes="atom">

And then of course your expression needs to be

<xsl:for-each select="count(tweets/atom:entry)" />

What does the below give you?

<xsl:for-each select="count(tweets/atom:entry)" />

Edit: Phoque wins.

That’s… amazing! It works now! Thanx!

But seriously, isn’t the documentation on dynamic datasources a bit… short? It would be great if there were some real-life examples like how to use atom-feeds from Twitter, Flickr, etc… And some explanation on namespaces.

Speaking of which: does anyone have some good articles for me to read on namespaces and namespace declarations? Because I can’t seem to wrap my head quite around it!

AHHHHH!!! okay, it shoud totally be noted ( in the tutorial too ) that ?debug will not allow these xpath expressions to function! I have spent sooo long on this! ug :\

Added to the list of things to be documented.

I am also having these problems. I am trying to import a popular links feed from Pinboard.in (just view Source). I have declared the namespaces in the datasource.

My XSLT:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
xmlns:content="http://purl.org/rss/1.0/modules/content/" 
xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" 
xmlns:dc="http://purl.org/dc/elements/1.1/" 
xmlns:cc="http://web.resource.org/cc/"  
xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" 
xmlns:admin="http://webns.net/mvcb/" >

<xsl:template match="data">
<xsl:value-of select="pinboard/rdf:RDF/item/title"/> // This is a test to see if it works. It doesn't.
<xsl:apply-templates select="pinboard"/>
</xsl:template>

<xsl:template match="pinboard">

PINBOARD
<dt><xsl:value-of select="rdf/channel/title"/></dt> // test1
<dt><xsl:value-of select="rdf:RDF/channel/title"/></dt> // test2
<dt><xsl:value-of select="rdf:RDF/item/title"/></dt> test3
    </xsl:template>
</xsl:stylesheet>

Any help?

@Ecko, it looks like you setup a Dynamic XML Datasource named Pinboard, so I went ahead and setup the datasource. Here’s a screenshot…

Dynamic XML datasource screenshot

in the xml for Pinboard you’ll notice that there is an empty namespace (or doesn’t have a namespace prefix), xmlns="http://purl.org/rss/1.0/"

 <rdf:RDF xmlns="http://purl.org/rss/1.0/"
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/"
        xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://web.resource.org/cc/"
        xmlns:syn="http://purl.org/rss/1.0/modules/syndication/"
        xmlns:admin="http://webns.net/mvcb/">  

Well, what I did in the XSL, is gave it the namespace rss in the stylesheet, like so, xmlns:rss="http://purl.org/rss/1.0/". That seems to solve the problem. And also make sure to to exclude the namespace prefixes in your XSL like so, exclude-result-prefixes="rss rdf content taxo dc cc syn admin"

Here’s the stylesheet…

<xsl:stylesheet version="1.0"
    xmlns:rss="http://purl.org/rss/1.0/"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:content="http://purl.org/rss/1.0/modules/content/" 
    xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" 
    xmlns:dc="http://purl.org/dc/elements/1.1/" 
    xmlns:cc="http://web.resource.org/cc/"  
    xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" 
    xmlns:admin="http://webns.net/mvcb/" exclude-result-prefixes="rss rdf content taxo dc cc syn admin">

    <xsl:output method="xml" 
                indent="yes" 
                encoding="UTF-8" 
                omit-xml-declaration="yes" />

    <xsl:template match="/">
        <html>
            <head>
                <title>Pinboard</title>
            </head>
            <body>
                <xsl:apply-templates select="data/pinboard"/>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="pinboard">
        <h1 class="channel-title"><xsl:value-of select="rdf:RDF/rss:channel/rss:title"/></h1>
        <p class="channel-description"><xsl:value-of select="rdf:RDF/rss:channel/rss:description"/></p>
        <ul>
            <xsl:apply-templates select="rdf:RDF/rss:channel/rss:items/rdf:Seq/rdf:li"/>
        </ul>
    </xsl:template>


    <xsl:template match="rdf:li">
        <li>
            <a href="{@rdf:resource}"><xsl:value-of select="@rdf:resource"/></a>
        </li>
    </xsl:template>

</xsl:stylesheet> 

By applying the stylesheet above to the Pinboard XML, you get the following output…

<html>
  <head>
    <title>Pinboard</title>
  </head>
  <body>
    <h1 class="channel-title">Pinboard (Popular items from Pinboard)</h1>
    <p class="channel-description">popular items from Pinboard</p>
    <ul>
      <li>
        <a href="http://duartes.org/gustavo/blog/post/what-your-computer-does-while-you-wait">http://duartes.org/gustavo/blog/post/what-your-computer-does-while-you-wait</a>
      </li>
      <li>
        <a href="http://www.gutenberg.org/wiki/Main_Page">http://www.gutenberg.org/wiki/Main_Page</a>
      </li>
      <li>
        <a href="http://meld.sourceforge.net/">http://meld.sourceforge.net/</a>
      </li>
      <li>
        <a href="http://lizzie.spod.cx/screenirssi.shtml">http://lizzie.spod.cx/screenirssi.shtml</a>
      </li>
      <li>
        <a href="http://www.sysinfo.org/startuplist.php">http://www.sysinfo.org/startuplist.php</a>
      </li>
      <li>
        <a href="http://www.facebook.com/common/browser.php">http://www.facebook.com/common/browser.php</a>
      </li>
      <li>
        <a href="http://lamb.cc/typograph/">http://lamb.cc/typograph/</a>
      </li>
      <li>
        <a href="place:folder=BOOKMARKS_MENU&amp;folder=UNFILED_BOOKMARKS&amp;folder=TOOLBAR&amp;sort=12&amp;excludeQueries=1&amp;excludeItemIfParentHasAnnotation=livemark%2FfeedURI&amp;maxResults=10&amp;queryType=1">place:folder=BOOKMARKS_MENU&amp;folder=UNFILED_BOOKMARKS&amp;folder=TOOLBAR&amp;sort=12&amp;excludeQueries=1&amp;excludeItemIfParentHasAnnotation=livemark%2FfeedURI&amp;maxResults=10&amp;queryType=1</a>
      </li>
      <li>
        <a href="place:sort=14&amp;type=6&amp;maxResults=10&amp;queryType=1">place:sort=14&amp;type=6&amp;maxResults=10&amp;queryType=1</a>
      </li>
      <li>
        <a href="http://mywiki.wooledge.org/BashPitfalls">http://mywiki.wooledge.org/BashPitfalls</a>
      </li>
      <li>
        <a href="http://jashkenas.github.com/coffee-script/">http://jashkenas.github.com/coffee-script/</a>
      </li>
      <li>
        <a href="http://coudal.com/perfect.php">http://coudal.com/perfect.php</a>
      </li>
      <li>
        <a href="place:sort=8&amp;redirectsMode=2&amp;maxResults=10">place:sort=8&amp;redirectsMode=2&amp;maxResults=10</a>
      </li>
      <li>
        <a href="http://www.theatlantic.com/magazine/archive/2003/03/caring-for-your-introvert/2696/">http://www.theatlantic.com/magazine/archive/2003/03/caring-for-your-introvert/2696/</a>
      </li>
      <li>
        <a href="http://lessframework.com/">http://lessframework.com/</a>
      </li>
      <li>
        <a href="http://jashkenas.github.com/coffee-script/#top">http://jashkenas.github.com/coffee-script/#top</a>
      </li>
      <li>
        <a href="http://code.google.com/p/emscripten/">http://code.google.com/p/emscripten/</a>
      </li>
      <li>
        <a href="http://www.good.is/post/americans-are-horribly-misinformed-about-who-has-money/">http://www.good.is/post/americans-are-horribly-misinformed-about-who-has-money/</a>
      </li>
      <li>
        <a href="http://documentcloud.github.com/backbone/">http://documentcloud.github.com/backbone/</a>
      </li>
      <li>
        <a href="http://programmers.stackexchange.com/questions/39/whats-your-favourite-quote-about-programming">http://programmers.stackexchange.com/questions/39/whats-your-favourite-quote-about-programming</a>
      </li>
      <li>
        <a href="http://littlebigdetails.com/">http://littlebigdetails.com/</a>
      </li>
      <li>
        <a href="http://cssgrid.net/">http://cssgrid.net/</a>
      </li>
      <li>
        <a href="http://lucumr.pocoo.org/2010/8/17/git-and-mercurial-branching/">http://lucumr.pocoo.org/2010/8/17/git-and-mercurial-branching/</a>
      </li>
      <li>
        <a href="http://letscrate.com/">http://letscrate.com/</a>
      </li>
      <li>
        <a href="http://www.kalzumeus.com/2010/12/12/staging-servers-source-control-deploy-workflows-and-other-stuff-nobody-teaches-you/">http://www.kalzumeus.com/2010/12/12/staging-servers-source-control-deploy-workflows-and-other-stuff-nobody-teaches-you/</a>
      </li>
      <li>
        <a href="http://www.teachparentstech.org/">http://www.teachparentstech.org/</a>
      </li>
      <li>
        <a href="http://hackety-hack.com/">http://hackety-hack.com/</a>
      </li>
      <li>
        <a href="http://ngrams.googlelabs.com/">http://ngrams.googlelabs.com/</a>
      </li>
      <li>
        <a href="http://en.wikipedia.org/wiki/Pixel_art_scaling_algorithms">http://en.wikipedia.org/wiki/Pixel_art_scaling_algorithms</a>
      </li>
      <li>
        <a href="http://www.sikuli.org/">http://www.sikuli.org/</a>
      </li>
      <li>
        <a href="http://stuff.veekun.com/pkcolor/">http://stuff.veekun.com/pkcolor/</a>
      </li>
      <li>
        <a href="http://royal.pingdom.com/2010/12/17/the-most-reliable-and-unreliable-blogging-services-2/">http://royal.pingdom.com/2010/12/17/the-most-reliable-and-unreliable-blogging-services-2/</a>
      </li>
      <li>
        <a href="http://kodapp.com/">http://kodapp.com/</a>
      </li>
      <li>
        <a href="http://blogs.wsj.com/speakeasy/2010/12/19/a-holiday-message-from-ricky-gervais-why-im-an-atheist/">http://blogs.wsj.com/speakeasy/2010/12/19/a-holiday-message-from-ricky-gervais-why-im-an-atheist/</a>
      </li>
      <li>
        <a href="http://www.economist.com/node/17722802?story_id=17722802">http://www.economist.com/node/17722802?story_id=17722802</a>
      </li>
      <li>
        <a href="http://www.volkside.com/2010/12/introducing-wirify-the-web-as-wireframes/">http://www.volkside.com/2010/12/introducing-wirify-the-web-as-wireframes/</a>
      </li>
      <li>
        <a href="http://www.sleepycity.net/posts/252/Demolition_of_the_Paris_Metro">http://www.sleepycity.net/posts/252/Demolition_of_the_Paris_Metro</a>
      </li>
      <li>
        <a href="http://www.theatlantic.com/technology/print/2010/12/the-hazards-of-nerd-supremacy-the-case-of-wikileaks/68217/">http://www.theatlantic.com/technology/print/2010/12/the-hazards-of-nerd-supremacy-the-case-of-wikileaks/68217/</a>
      </li>
      <li>
        <a href="http://www.comicsanscriminal.com/">http://www.comicsanscriminal.com/</a>
      </li>
      <li>
        <a href="http://52weeksofux.com/post/2403607066/building-a-shared-understanding">http://52weeksofux.com/post/2403607066/building-a-shared-understanding</a>
      </li>
    </ul>
  </body>
</html>

@Ecko, did that help out?

Oh yes! That helped me greatly. I was just busy over the weekend. Anyway, the purpose of importing this feed for me was that I was hoping I would use it as a linklog source, but I am running into problems how to include tags.

I will study the code. Thanks again.

Cool. I’m glad it was helpful.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details