Copied to clipboard

Flag this post as spam?

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


  • jayanthi 66 posts 86 karma points
    Sep 07, 2011 @ 17:27
    jayanthi
    0

    Grouping by year

    Hi all,

    I am trying to categorize or group my press releases based on the year of publishing.When i am using key 'year' (i.e; using formatdatetime )the results are not coming. and when using key 'uniquedate' duplicate years are appearing,can anyone let me know what is the error?

     

    <xsl:output method="xml" omit-xml-declaration="yes"/>

      <xsl:param name="currentPage"/>
      <xsl:key name="uniqueDate" match="PressRelease" use="pressPublishDate"/>
      <xsl:key name="year" match="PressRelease" use="umbraco.library:FormatDateTime(pressPublishDate,'YYYY')"/>
      <xsl:key name="kNewsByY" match="PressRelease" use="Exslt.ExsltDatesAndTimes:year(pressPublishDate)"    />
     
      <xsl:template match="/">

        <xsl:for-each select="$currentPage/child::*[generate-id() = generate-id(key('year', umbraco.library:FormatDateTime(pressPublishDate,'YYYY'))[1])]">
          <xsl:value-of select="substring(pressPublishDate, 1, 4)"/>

         <br/>
        </xsl:for-each>
        <div class="subnavTabs clearfix" id="subNavTabs">
          <ul>
            <xsl:apply-templates select="$currentPage/child::*[generate-id() = generate-id(key('uniqueDate', pressPublishDate)[1])]" mode="PressRelease">
              <xsl:sort select="pressPublishDate" order="descending" />
            </xsl:apply-templates>
          </ul>
         
        </div>
     
        <!--<xsl:for-each select="$currentPage/child::*">
          <xsl:value-of select="pressPublishDate"/>

          <xsl:value-of select="substring(pressPublishDate, 1,4)"/>
          <br/>
        </xsl:for-each>-->

      </xsl:template>
      <xsl:template match="PressRelease" mode="PressRelease">
        <xsl:variable name="PublishDate">
          <xsl:value-of select="substring(pressPublishDate, 1, 4)" />
        </xsl:variable>

        <xsl:variable name="DivId" select="concat('Div',$PublishDate)" />

        <li>
          <xsl:attribute name="id">
            <xsl:if test="$PublishDate = '2010'">
              <xsl:text>current</xsl:text>
            </xsl:if>
          </xsl:attribute>

          <a href="javascript:Toggle();">
            <xsl:attribute name="onclick">
              <xsl:value-of select="concat('ShowTab(',$DivId,',this);')"/>
            </xsl:attribute>
            <xsl:value-of select="$PublishDate"/>
          </a>
        </li>

      </xsl:template>

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Sep 08, 2011 @ 11:54
    Chriztian Steinmeier
    0

    Hi jayanthi,

    Your keys will most likely perform better without the library call, e.g.:

    <xsl:key name="year" match="PressRelease" use="substring(pressPublishDate, 1, 4)" /> 

    and the lookup:

    <xsl:for-each select="$currentPage/*[generate-id() = generate-id(key('year', substring(pressPublishDate, 1, 4))[1])]">

    It's hard to say what's going wrong but context is everything in XSLT, especially when using keys, so maybe you can show some of your XML too?

    /Chriztian

  • jayanthi 66 posts 86 karma points
    Sep 08, 2011 @ 17:16
    jayanthi
    0

    Hi Chriztian,

     

    Please find my sample xml.My content node xyz contains the child node press releases .I want to categorize all the press releases based on the year of published date(pressPublishDate).Can you please help me now?

     

    <?xml version="1.0" encoding="utf-8" ?>
    <Content id="1149" parentID="1101" level="4" writerID="2" creatorID="0" nodeType="1087" template="1177" sortOrder="3" createDate="2011-06-09T16:35:31" updateDate="2011-08-30T12:31:08" nodeName="xyz" urlName="blah" writerName="blah" creatorName="admin" path="-1,1092,1093,1101,1149" isDoc="">
      <pageModuleHeader>blah</pageModuleHeader>
      <pageHeader>blah</pageHeader>
      <pageImage>blah</pageImage>
      <pageImageDescription>blah</pageImageDescription>
       <bodyMaincontent><![CDATA[]]></bodyMaincontent>
      <linkText>blah</linkText>
      <umbracoNaviHide>0</umbracoNaviHide>
      <umbracoUrlAlias>
      </umbracoUrlAlias>
      <umbracoRediract>
      </umbracoRediract>
      <pageTitle>blah</pageTitle>
      <pageFooterFillingNumber>1 </pageFooterFillingNumber>
      <pageFooterFillingDate>10/19/2010</pageFooterFillingDate>
      <PressRelease id="1172" parentID="1149" level="5" writerID="2" creatorID="0" nodeType="1134" template="1180" sortOrder="1" createDate="" updateDate="" nodeName="blah" urlName="blah" writerName="blah" creatorName="admin" path="-1,1092,1093,1101,1149,1172" isDoc="">
        <pressPublishDate>2010-10-19T00:00:00</pressPublishDate>
        <pressDescription>blah
          <![CDATA[blah]]>
        </pressDescription>
        <pressNotes><![CDATA[October, 2010 ]]></pressNotes>
        <pressReleaseSortOrder />
        <pageModuleHeader>blah</pageModuleHeader>
        <pageHeader>blah</pageHeader>
        <pageImage>blah</pageImage>
        <pageImageDescription>blah</pageImageDescription>
      
        <bodyMaincontent>
          <![CDATA[
    blah blah
    blah
    blah
    ]]>
        </bodyMaincontent>
        <linkText />
        <umbracoNaviHide>0</umbracoNaviHide>
        <umbracoUrlAlias />
        <umbracoRediract />
        <pageTitle>blah</pageTitle>
        <pageFooterFillingNumber>2</pageFooterFillingNumber>
        <pageFooterFillingDate>10/19/2010</pageFooterFillingDate>
      </PressRelease>
      <PressRelease id="1174" parentID="1149" level="5" writerID="2" creatorID="0" nodeType="1134" template="1180" sortOrder="2" createDate="2011-06-15T18:03:45" updateDate="2011-09-07T19:22:53" nodeName="blah" urlName="blah" writerName="blah" creatorName="admin" path="-1,1092,1093,1101,1149,1174" isDoc="">
        <pressPublishDate>2009-01-08T00:00:00</pressPublishDate>
        <pressDescription><![CDATA[blah]]></pressDescription>
        <pressNotes><![CDATA[January, 2009 ]]></pressNotes>
        <pressReleaseSortOrder>9</pressReleaseSortOrder>
        <pageModuleHeader>blah</pageModuleHeader>
        <pageHeader>blah</pageHeader>
        <pageImage>blah</pageImage>
        <pageImageDescription>blah</pageImageDescription>
      
        <bodyMaincontent>
          <![CDATA[
    blah blah blah
    blah blah blah
    ]]>
        </bodyMaincontent>
        <linkText />
        <umbracoNaviHide>0</umbracoNaviHide>
        <umbracoUrlAlias />
        <umbracoRediract />
        <pageTitle>
          blah blah blah
        </pageTitle>
        <pageFooterFillingNumber>1</pageFooterFillingNumber>
        <pageFooterFillingDate>01/08/2009</pageFooterFillingDate>
      </PressRelease>
    </Content>

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Sep 08, 2011 @ 20:52
    Chriztian Steinmeier
    0

    Hi jayanthi,

    Just realized that your code will only work when executed on the parent page of the PressRelease pages (e.g. the "xyz" node of your sample XML) - are you running the macro on that page?

    /Chriztian 

  • jayanthi 66 posts 86 karma points
    Sep 08, 2011 @ 21:59
    jayanthi
    0

    Yes....My macro is specific to that xyz page only.....Can you please let me know why iam not able to get the expected result?I am not sure what is going wrong on my xslt.... Please thow some light on this.

  • jayanthi 66 posts 86 karma points
    Sep 09, 2011 @ 14:36
    jayanthi
    0

    I have tried many ways but nothing working my way...

  • jayanthi 66 posts 86 karma points
    Sep 14, 2011 @ 15:31
    jayanthi
    0

    I got it worked .With the following change

    <xsl:variable name="data" select="umbraco.library:GetXmlAll()//node()/PressRelease[@isDoc and isArticle='1']"/>

    <xsl:apply-templates select="$data[(generate-id()=generate-id(key('years', Exslt.ExsltDatesAndTimes:year(pressPublishDate))[1]))]" mode="YearDisplay">

Please Sign in or register to post replies

Write your reply to:

Draft