View unanswered posts | View active topics

Reply to topic  [ 4 posts ] 

Joined: Wed Oct 19, 2011 5:22 pm
Posts: 2
Post urls rewriting
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


Thu Oct 20, 2011 11:31 am
Profile
Site Admin
User avatar

Joined: Fri Feb 07, 2003 8:48 am
Posts: 2883
Location: Melbourne, Australia
Post Re: urls rewriting
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.


Sat Oct 22, 2011 10:56 pm
Profile WWW
User avatar

Joined: Mon Sep 08, 2008 3:16 pm
Posts: 222
Location: Elk Grove, California
Post Re: urls rewriting
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:
<?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>


Sun Oct 23, 2011 3:10 am
Profile

Joined: Wed Oct 19, 2011 5:22 pm
Posts: 2
Post Re: urls rewriting
Thank you for your straightforward answers and ready to use solution. Definitively a wonderfull world!


Tue Oct 25, 2011 12:38 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online
Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron