Copied to clipboard

Flag this post as spam?

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


  • Connie DeCinko 931 posts 1160 karma points
    May 13, 2011 @ 22:08
    Connie DeCinko
    0

    One RSS Template, Multiple XSLTs?

    I've created my first RSS feed, customized for a specific document type.  I'd like to use the same RSS template site wide, but have it call a different customized macro/XSLT.  Or, I could have one large XSLT file with conditional templates?

    What are some ideas of how to condense and streamline my future feeds?

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 13, 2011 @ 22:50
    Chriztian Steinmeier
    0

    Hi Connie,

    It should be quite possible to use a single file for this - consider this (pseudo XSLT):

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet ...>
    
        <xsl:param name="currentPage" />
        <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    
        <xsl:variable name="section" select="/macro/section" />
    
        <xsl:template match="/">
            <rss>
                <xsl:apply-templates select="$siteRoot/*[name() = $section]" />
            </rss>
        </xsl:template>
    
        <xsl:template match="NewsList">
            <channel>
                <!-- top level stuff for News RSS -->
    
                <!-- do the items -->
                <xsl:apply-templates select="NewsItem">
                    <xsl:sort select="@updateDate" data-type="text" order="descending" />
                </xsl:apply-templates>
            </channel>
        </xsl:template>
    
        <xsl:template match="EventsCalendar">
            <channel>
                <!-- top level stuff for Events RSS -->
                <xsl:apply-templates select="Event">
                    <xsl:sort select="eventDate" data-type="text" order="ascending" />
                </xsl:apply-templates>
            </channel>
        </xsl:template>
    
        <xsl:template match="NewsItem">
            <item>
                <!-- do the News entry -->
            </item>
        </xsl:template>
    
        <xsl:template match="Event">
            <item>
                <!-- do the News entry -->
            </item>
        </xsl:template>
    
    </xsl:stylesheet>

    This file could generate two separate RSS feeds, by supplying a macro parameter with the name of the section to process.  

    /Chriztian

  • Connie DeCinko 931 posts 1160 karma points
    May 14, 2011 @ 00:10
    Connie DeCinko
    0

    I like your idea.  I haven't used templates much, but now see the power in them. 

    I'm having a problem using this however.  If I take the variables out of the if statement, they work.  The id is correct.  Even testing for 1=1 does not work.

        <xsl:if test="$currentPage/* [@id=3530]">
          <xsl:variable name="rssTitle" select="'Arizona Attorney Magazine News Center'" />
          <xsl:variable name="documentTypeAlias" select="'LegalNewsHeadline'" />
          <xsl:variable name="numberOfItems" select="'20'" />
          <xsl:variable name="rssDescription" select="'Headlines gathered by the Arizona Attorney Magazine staff'" />
          <xsl:variable name="rssLanguage" select="'English'" />
        </xsl:if>
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 14, 2011 @ 16:50
    Chriztian Steinmeier
    0

    Hi Connie,

    The reason that doesn't work is because you're probably trying to access the variable outside of the <xsl:if>, but unfortunately they're no longer in scope by then...

    If you need deifferent values for the different feeds, try this approach - creating an XML "mapper" variable that you can query for the needed data:

    <xsl:variable name="channel-mapper">
        <channel id="3530">   
            <rssTitle>Arizona Attorney Magazine News Center</rssTitle>
            <documentTypeAlias>LegalNewsHeadline</documentTypeAlias>
            <numberOfItems>20</numberOfItems>
            <rssDescription>Headlines gathered by the Arizona Attorney Magazine staff</rssDescription>
            <rssLanguage>English</rssLanguage>
        </channel>
        <channel id="3802">   
            <rssTitle>Other title</rssTitle>
            <documentTypeAlias>LegalNewsHeadline</documentTypeAlias>
            <numberOfItems>20</numberOfItems>
            <rssDescription>Headlines for other stuff</rssDescription>
            <rssLanguage>English</rssLanguage>
        </channel>
    </xsl:variable>
    <xsl:variable name="channelData" select="make:node-set($channel-mapper)/channel" />
    
    <xsl:template match="/">
        <xsl:variable name="currentChannel" select="channelData/channel[@id = $currentPage/@id]" />
    
        <!-- Output stuff from the currentChannel -->
        <xsl:value-of select="$currentChannel/rssTitle" />
    
    </xsl:template>
    

    /Chriztian 

Please Sign in or register to post replies

Write your reply to:

Draft