manuel
Posts: 2
Joined: Wed Oct 19, 2011 9:22 pm

Postby manuel » Thu Oct 20, 2011 3:31 pm

Hello,
Does anybody ever attempt to rewrite story urls of a particular feed?
For example from something like

http://actus.gregit.com/actus/url?sa=t& ... ng-renamed

to http://www.citytv.com/toronto/citynews/ ... ng-renamed

Any help would be appreciated
Thx

User avatar
support
Site Admin
Posts: 3021
Joined: Fri Feb 07, 2003 12:48 pm
Location: Melbourne, Australia
Contact:

Postby support » Sun Oct 23, 2011 2:56 am

manuel wrote:Does anybody ever attempt to rewrite story urls of a particular feed?

You can do it using XSL (kevotheclone is better at this stuff than I am and he'll probably chime in with info on how to do it), or you can write a little plugin to do it.

Look at the online help for info on how to do this - it's pretty simple. If you define a parameter called DownloadUrl, Awasu will download the specified URL for you (more info here). Your plugin can then read it in, fix up all the URL's, then print out the adjusted feed for Awasu to read.

User avatar
kevotheclone
Posts: 239
Joined: Mon Sep 08, 2008 7:16 pm
Location: Elk Grove, California

Postby kevotheclone » Sun Oct 23, 2011 7:10 am

Great idea! Wish I'd thought of it
Google News feeds do this same type of thing where all links are first routed to Google so they can track your clicks. :drevil:

(I'm no expert, but...) The XSLT file below should work for the example URLs that you (manuel) provided as well Google News feeds since both prefix the actual URL with a url= named parameter.

If needed you can change the value of <xsl:variable name="UrlPrefix">url=</xsl:variable> to process other feeds that use a different prefix before the actual URL.

Once again this kind of processing only exists within the Wonderful World Of Awasu! :D

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:variable name="UrlPrefix">url=</xsl:variable>
  <!--
  Matches everything not specified elseware; copies it to the output.
  -->
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template> 
 
  <!--
  Matches the root node and "gets the party started".
  -->
  <xsl:template match="/">
    <xsl:apply-templates></xsl:apply-templates>
  </xsl:template>
 
  <!--
  Matches RSS <link> elements.
  -->
  <xsl:template match="/rss/channel/item/link">
    <xsl:element name="{name(.)}">
      <xsl:choose>
        <xsl:when test="contains(., $UrlPrefix)">
          <xsl:value-of select="substring-after(., $UrlPrefix)"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates/>
        </xsl:otherwise>
      </xsl:choose>

    </xsl:element>
  </xsl:template>

  <!--
  Matches Atom <link> elements.
  -->
  <xsl:template match="/atom:feed/atom:entry/atom:link/@href">
      <xsl:choose>
        <xsl:when test="contains(., $UrlPrefix)">
          <xsl:value-of select="substring-after(., $UrlPrefix)"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates/>
        </xsl:otherwise>
      </xsl:choose>
  </xsl:template>

</xsl:stylesheet>

manuel
Posts: 2
Joined: Wed Oct 19, 2011 9:22 pm

Postby manuel » Tue Oct 25, 2011 4:38 pm

Thank you for your straightforward answers and ready to use solution. Definitively a wonderfull world!


Return to “Awasu - Feature Requests”

Who is online

Users browsing this forum: No registered users and 4 guests