Copied to clipboard

Flag this post as spam?

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


  • Sushma 12 posts 32 karma points
    Oct 12, 2011 @ 15:28
    Sushma
    0

    Display articles based on a value

    Hi all,

    In my table i have fixed the width which fits a maximum of 7 tabs.

    In XSLT code  i am  displaying articles by year by taking year as a tab.If i want to add articles of a new year, alignment of tabs gets disturbed.

    So,i want a generic code which can display the tabs(year) by giving a value(means, if i give 1 the top most year articles only should display,if 2 top two years tabs,.....10 top ten years tabs) so that i can display them on requiremnt.Whole code should be handled in XSLT itself.

    <?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 omit-xml-declaration="yes" indent="yes"/>
      <xsl:param name="currentPage"/>
      <xsl:key name="years" match="PressRelease[@isDoc and isArticle='1']"  use="Exslt.ExsltDatesAndTimes:year(pressPublishDate)"/>
      <xsl:key name="months" match="PressRelease[@isDoc and isArticle='1']" use="substring(pressPublishDate, 7, 10)"/>
      <xsl:variable name="data" select="umbraco.library:GetXmlAll()//node()/PressRelease[@isDoc and isArticle='1']"/>

      <xsl:template match="/">
      
      
        <div class="subnavTabs clearfix" id="subNavTabs" >
          <ul>
              <xsl:apply-templates select="$data[(generate-id()=generate-id(key('years', Exslt.ExsltDatesAndTimes:year(pressPublishDate))[1]))]" mode="YearDisplay">
              <xsl:sort select="pressPublishDate" order="descending"/>
            </xsl:apply-templates>
            <li>
                 <a href="javascript:Toggle();" onClick="showAll(this);">Show All</a>
             </li>
           </ul>
        </div>
      
       <xsl:for-each select="$data[(generate-id()=generate-id(key('years', Exslt.ExsltDatesAndTimes:year(pressPublishDate))[1]))]">
          <xsl:sort select="pressPublishDate" order="descending"/>
        
          <xsl:call-template name="ArticlesByMonth">
            <xsl:with-param name="ArticleYear" select="Exslt.ExsltDatesAndTimes:year(pressPublishDate)"></xsl:with-param>  
          </xsl:call-template>
        </xsl:for-each>
        
      </xsl:template>

      <xsl:template match="PressRelease" mode="YearDisplay">
        <xsl:variable name="PublishDate">
          <xsl:value-of select="Exslt.ExsltDatesAndTimes:year(pressPublishDate)"/>
        </xsl:variable>
           <xsl:variable name="DivId" select="concat('Div',$PublishDate)" />  
        
              <xsl:variable name="sortedItems">
                <xsl:for-each select="$currentPage/..//*[@isDoc  and isArticle='1']">
                   <xsl:sort select="pressPublishDate" order="descending" />   
                   <xsl:copy-of select="." />
                </xsl:for-each>
              </xsl:variable>
          
      
            <li>
            <xsl:if test="position()=1">
              <xsl:attribute name="id">
                <xsl:text>current</xsl:text>
              </xsl:attribute>
              <xsl:value-of select="substring(./data [@alias = 'id'],1,7)" disable-output-escaping="yes"/>
        
            </xsl:if>
                        <a href="javascript:Toggle();">
             <xsl:attribute name="id" >
             <xsl:value-of select="concat($DivId,'_1')"/>
                 </xsl:attribute>
                      <xsl:attribute name="onclick">
         
               </xsl:attribute>
            <xsl:value-of select="$PublishDate"/>
            </a>
            </li>
      </xsl:template>

        <xsl:template match="PressRelease" mode="MonthDisplay">
        <xsl:variable name="PublishYear">
          <xsl:value-of select="Exslt.ExsltDatesAndTimes:year(pressPublishDate)"/>
        </xsl:variable>
        <xsl:variable name="PublishDate">
          <xsl:value-of select="substring(pressPublishDate, 7, 10)"/>
        </xsl:variable>
        <xsl:variable name="DivId" select="concat('Div',$PublishYear)" />
        <div>
          <xsl:attribute  name="id">
            <xsl:value-of select="$DivId"/>
          </xsl:attribute>
           <xsl:for-each select="$data[@isDoc  and isArticle='1']">
              <xsl:variable name="child" select="umbraco.library:GetXmlNodeById(@id)[@isDoc] "/>
               <xsl:if test="substring(pressPublishDate, 7, 10) = $PublishDate">
                <P align="left">
                  <a href="{umbraco.library:NiceUrl(@id)}">
                    <xsl:value-of select="$child/pressDescription"/>
                  </a>
                  <br/>
                  <xsl:value-of select="$child/pressNotes"/>
                 <br />
                </P>
              </xsl:if>
            </xsl:for-each>
        </div>
      </xsl:template>
      <xsl:template name="ArticlesByMonth">
        <xsl:param name="ArticleYear" />
          <xsl:variable name="PublishDate">
            <xsl:value-of select="substring(pressPublishDate, 7, 10)" />
          </xsl:variable>
          <xsl:variable name="DivId" select="concat('Div',$ArticleYear)" />
          <div>
             <xsl:attribute  name="id">
                <xsl:value-of select="$DivId"/>
             </xsl:attribute>
             <br/>
             <br/>
              <xsl:for-each select="$currentPage/descendant::* [@isDoc and isArticle='1'and Exslt.ExsltDatesAndTimes:year(pressPublishDate) = $ArticleYear]">
              <xsl:variable name="child" select="umbraco.library:GetXmlNodeById(@id)[@isDoc] "/>
                 <P align="left">
                    <a href="{umbraco.library:NiceUrl(@id)}">
                      <xsl:value-of select="$child/pressDescription"/>
                    </a>
                    <br/>
                      <xsl:value-of select="$child/pressNotes"/>
                   
                    
                </P>
               </xsl:for-each>

          <script type="text/javascript">
            addLoadEvent(init);
          </script>
              </div>
      </xsl:template>
    </xsl:stylesheet>
Please Sign in or register to post replies

Write your reply to:

Draft