Copied to clipboard

Flag this post as spam?

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


  • Kris Dyson 54 posts 79 karma points
    Mar 11, 2010 @ 17:33
    Kris Dyson
    0

    Merge node sets

    Hi there, I want to merge to rss feed resultsets, then order them... is this possible with xslt?

        <xsl:variable name="rss1" select="umbraco.library:GetXmlDocumentByUrl('http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml')" /> 
    <xsl:variable name="rss2" select="umbraco.library:GetXmlDocumentByUrl('http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/uk_politics/rss.xml')" />

    Ideally I'd like to merge the results, order them by date and then output the first 30 items,

    It's the merging bit that I'm struggling with - any suggestions?

    thanks

    Kris


     

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Mar 11, 2010 @ 17:46
    Douglas Robar
    0

    Off the top of my head (which means I haven't tried this), can you create a union of the feeds with this?

    <xsl:variable name="feeds" select="umbraco.library:GetXmlDocumentByUrl('someUrl1') | umbraco.library:GetXmlDocumentByUrl('someUrl2')" />

    Then you'd have a single variable of everything that you could <xsl:for-each> and <xsl:sort>.

    cheers,
    doug.

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Mar 11, 2010 @ 18:21
    Douglas Robar
    0

    Thinking another minute about this... you might need to add a wrapping xml element around the whole thing to avoid having two root elements (one from each rss feed). To do that you should be able to do something like:

    <xsl:variable name="feeds" select="concat('&lt;feeds>', umbraco.library:GetXmlDocumentByUrl() | umbraco.library:GetXmlDocumentByUrl(), '&lt;/feeds>')" />

    Hope these little snippets of ideas help out.

     

    cheers,
    doug

  • Kris Dyson 54 posts 79 karma points
    Mar 11, 2010 @ 18:21
    Kris Dyson
    0

    Hi Doug, thanks for this. However, the feeds are not static, they come from a list of rss feeds that the user has selected.

    I wonder if it's possible to create an xml doc in XSLT, importing nodes from GetXmlDocumentByUrl and storing the result in a variable... then it would be possible to do a xsl:sort

    k

  • Kris Dyson 54 posts 79 karma points
    Mar 11, 2010 @ 18:26
    Kris Dyson
    0

    do you know if it's possible to store inline xml in a variable?

     

        <xsl:variable name="rssFeeds">
          <container>
            <hello></hello>
          </container>
        </xsl:variable>

     

    I cannot do this at the moment, i get 'To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set() function. at System.Xml.Xsl.Runtime.XsltConvert.EnsureNodeSet...'

     

  • Kris Dyson 54 posts 79 karma points
    Mar 11, 2010 @ 18:29
    Kris Dyson
    0

    oh it's OK, that's my fault that didn't work!

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Mar 11, 2010 @ 18:31
    Douglas Robar
    0

    Also might need to use the msxsl:node-set() around the whole thing.

    cheers,
    doug.

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Mar 11, 2010 @ 18:34
    Douglas Robar
    0

    It will get a bit more tricky to do it all in xslt but it isn't impossible by any means.

    Catch me up on what you've got so far and if there's anything left to resolve. I (or any of a large number of other folks in the community) are happy to help.

    cheers,
    doug.

  • Kris Dyson 54 posts 79 karma points
    Mar 11, 2010 @ 18:44
    Kris Dyson
    0

    Hi Doug, think I have worked it out...

     

        <xsl:variable name="rssFeeds">
          <container>
            <xsl:copy-of select="umbraco.library:GetXmlDocumentByUrl($url)"/>
            <xsl:copy-of select="umbraco.library:GetXmlDocumentByUrl($url2)"/>
            <xsl:copy-of select="umbraco.library:GetXmlDocumentByUrl($url3)"/>
          </container>
        </xsl:variable>

     


     

       <xsl:for-each select="msxsl:node-set($rssFeeds)/container/rss/channel/item">
          <xsl:sort select="pubDate" order="descending"/>

          <xsl:if test="position() &lt;= 30">
            <h1>
              <a>
                <xsl:attribute name="href">
                  <xsl:value-of select="link/text()"/>
                </xsl:attribute>
                <xsl:value-of select="title/text()"/>
              </a>
            </h1>
            <p>
              <xsl:value-of select="description/text()" />
            </p>
          </xsl:if>
          
        </xsl:for-each>

     

     

    This seems to work OK, it was that I didn't use node-set in the correct place.  

    We have a system wide set of RSS feeds, and users select the ones they want.  The RSS feeds are Nodes under Content like anything else and the when the user selects one to subscribe to, the content node id is set into a CSV property of the member profile (just a CSV list of node ids of rss feeds)

    So for my next trick, I'm going to attempt to loop through the subscribed rss feeds' node ids in the member type and then pull the url from the content node, then use library:GetXmlDocumentByUrl to get the xml and import it

    Hope there's some way to deal with CSV in XSLT :-)  

    Kris

  • Kris Dyson 54 posts 79 karma points
    Mar 11, 2010 @ 18:48
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies