Search

After looking through the other "grouping" threads, I still can't wrap my head around this particular problem.

I'm trying to integrate a blogger feed into Symphony as a dynamic data source. Blogger sends huge amounts of metadata with each entry, and I only need to grab two nodes from each entry. An abbreviated example:

<feed>
<entry>
    <id>XXX</id>
    <published>XXX</published>
    <title>Entry Title</title>
    <link rel="replies" href="comments-link"/>
    <link rel="alternate" href="http://link-to-post.com"/>
</entry>
</feed>

I have an XPath query that pulls only the title and link elements with attribute 'alternate'. See here (namespace of the blogger feed is 'atom'):

(atom:feed/atom:entry/atom:title | atom:feed/atom:entry/atom:link[@rel = 'alternate'])

This works to get only the two elements I need, but takes away the parent grouping, ie:

<blogger-feed>
    <title>stuff</title>
    <link href="url"/>
    <title>things</title>
    <link href="url"/>
</blogger-feed>

How can I go about retaining that parent element in my XPath expression? I've tried using following-sibling:: in my XSL, but it's been a hassle to get working. I'm sure my XPath union thingy is just wrong.

I'm trying to reduce the returned node set because when the feed isn't cached, the page takes quite a while to load the huge blogger feed unless I strip it down.

@haircut - Since you are wanting data for each entry, you will have to pull each entry in the Dynamic XML. So, from my understanding, you won’t be able to do that with Dynamic XML DS’s and XPath.

Here’s one option. You can setup another PAGE, and set it up as XML and also make it hidden so it won’t show up in your navigation.

In the XML PAGE TEMPLATE, put the following code in the template.

<?xml version="1.0" encoding="UTF-8" ?>
<!--
    Blogger XML Page
-->

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:atom="http://www.w3.org/2005/Atom"
                xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" 
                xmlns:georss="http://www.georss.org/georss"
                xmlns:thr="http://purl.org/syndication/thread/1.0">

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

    <xsl:template match="/">
        <xsl:variable name="blogger-feed" select="'http://blogsofnote.blogspot.com/feeds/posts/default'"/>

        <blogger-feed>
            <xsl:apply-templates select="document($blogger-feed)/atom:feed/atom:entry"/>
        </blogger-feed>

    </xsl:template>

    <xsl:template match="atom:entry">
        <entry>
            <title><xsl:value-of select="atom:title"/></title>
            <link href="{atom:link[@rel = 'alternate']/@href}"/>
        </entry>
    </xsl:template>
</xsl:stylesheet>

Then you could setup a Dynamic XML DS pointing to this XML PAGE.

NOTE: With this piece of code, <xsl:variable name="blogger-feed" select="'http://blogsofnote.blogspot.com/feeds/posts/default'"/>, make sure to change the URL to YOUR feed

@haircut - OR you could just make a basic XSLT utility…

<?xml version="1.0" encoding="UTF-8" ?>
<!--
    Blogger Call Template Utility
-->

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:atom="http://www.w3.org/2005/Atom"
                xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" 
                xmlns:georss="http://www.georss.org/georss"
                xmlns:thr="http://purl.org/syndication/thread/1.0">

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

    <!--
        To use, just call the template blogger-feed (default count is 5, if want to change count, just call with-param and select another number like so...

        <xsl:call-template name="blogger-feed">
            <xsl:with-param name="feed-url" 
                select="'http://blogsofnote.blogspot.com/feeds/posts/default'"/>
            <xsl:with-param name="count" select="8" />
        </xsl:call-template>

    -->

    <xsl:template name="blogger-feed">
        <xsl:param name="feed-url"/>
        <xsl:param name="count" select="5"/>

        <div class="blogger-feed">
            <xsl:apply-templates select="document($feed-url)/atom:feed/atom:entry[position() &lt;= $count]"/>
        </div>

    </xsl:template>

    <xsl:template match="atom:entry">
        <ul class="blogger-entry">
            <li>
                <a href="{atom:link[@rel = 'alternate']/@href}" title="{atom:title}">
                    <xsl:value-of select="atom:title"/>
                </a>
            </li>
        </ul>
    </xsl:template>
</xsl:stylesheet>

Then just import that utility at the top of your page…

Then call that template like so in your page…

<xsl:call-template name="blogger-feed">
   <xsl:with-param name="feed-url" 
                select="'http://blogsofnote.blogspot.com/feeds/posts/default'"/>
    <xsl:with-param name="count" select="3" />
</xsl:call-template>

This will return 3 entries. The count parameter is optional, because in the utility I have it defaulting to 5 entries.

Hopefully that helps.

@bzerangue - WOW, thank you! That first method worked perfectly. I owe you one.

thats interesting i wasn’t aware that xml pages could be used as datasources!

@Treemonkey - nor was I, but it makes sense! Another reason Symphony rocks.

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