Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Adam Jenkin 71 posts 226 karma points
    May 17, 2011 @ 15:39
    Adam Jenkin
    0

    Processing Twitter ATOM results with XSLT

    I am trying to process ATOM search results from twitter using the umbraco.library:GetXmlDocumentByUrl.

    I have very much copied the approach from the Twitter4Umbraco project where I know this works, however when applying this to the ATOM search xml, I am having difficulty using xpath to drill down into the document.

    Here is what I have:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet 
     version="1.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns:msxml="urn:schemas-microsoft-com:xslt"
     xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" 
     exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
    
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    
    <xsl:param name="currentPage"/>
    
    <xsl:template match="/">
    
      <xsl:variable name="MyFeed" select="umbraco.library:GetXmlDocumentByUrl('http://search.twitter.com/search.atom?q=umbraco')" />
    
      <!-- this works - shows me the contents of the variable -->
      <textarea>
        <xsl:copy-of select="$MyFeed" />
      </textarea>
    
      <br />
      
      <!-- this doesn't :( -->
      <textarea>
        <xsl:copy-of select="$MyFeed//feed/entry" />
      </textarea>
      
      <!-- Once its working, I want to-do something like this -->
      <xsl:for-each select="$MyFeed//feed/entry">
        <xsl:apply-templates mode="result" select="current()"/>
      </xsl:for-each>
    
    </xsl:template>
    
    <xsl:template match="entry" mode="result">
    
      <!-- Once I'm here, I can do my stuff! but for now .. -->
      <div>
        <p>
          <xsl:value-of select="title" />
        </p>
      </div>
     
    </xsl:template>
    
    </xsl:stylesheet>

    Im pretty sure its got somehting todo witht the namespaces being used in the document held in the variable, however i'm losing the plot a little trying to get this to work!

    Any help much appreciated.

    Thanks,

    Adam

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    May 17, 2011 @ 17:35
    Chriztian Steinmeier
    2

    Hi Adam,

    You are indeed right - namespaces are trippin' you up; but easy to fix:

    Add the namespace declarations from the source to your XSLT - choose a prefix for the atom namespace too, and do something like this:

    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet 
        version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:atom="http://www.w3.org/2005/Atom"
        xmlns:twitter="http://api.twitter.com/"
        xmlns:umbraco.library="urn:umbraco.library" 
        exclude-result-prefixes="msxml umbraco.library atom twitter"
    >
    
        <xsl:output method="xml" omit-xml-declaration="yes"/>
    
        <xsl:param name="currentPage"/>
    
        <xsl:template match="/">
    
        <xsl:variable name="MyFeed" select="umbraco.library:GetXmlDocumentByUrl('http://search.twitter.com/search.atom?q=umbraco')" />
    
        <xsl:template match="/">
            <xsl:apply-templates select="$MyFeed//atom:entry" />
        </xsl:template>
    
        <xsl:template match="atom:entry">
            <div>
                <p>
                    <xsl:value-of select="atom:title" />
                </p>
            </div>
        </xsl:template>
    
    </xsl:stylesheet>

    /Chriztian

  • Adam Jenkin 71 posts 226 karma points
    May 18, 2011 @ 11:00
    Adam Jenkin
    0

    Many Thanks Chriztian - All working now :)

Please Sign in or register to post replies

Write your reply to:

Draft