Copied to clipboard

Flag this post as spam?

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


  • Martin 278 posts 662 karma points
    Feb 06, 2012 @ 15:06
    Martin
    0

    DateFolders XSLT Issues

    Hi, 
    Im having issues with my DateFolders XSLT.

    Im trying to output code that looks like

    2012
    > January
    >>News Item
    >>News Item
    > Febuary
    >>News Item
    >>News Item

    Ive tried to split the DateFolder up into years, months and news items in variables, but i still keep getting either repeated news items or issues with the months.

    Has anyone used the DateFolders package and could help me wit the XSLT.

    Thanks

    Martin

     

     

    <xsl:param name="currentPage"/>
        
        <xsl:variable name="newsYear" select="$currentPage/ancestor-or-self::* /itemDocType//DateFolder [@isDoc]"/>
        <xsl:variable name="newsMonth" select="$currentPage/ancestor-or-self::* /itemDocType//DateFolder [@level='4'] [@isDoc]"/>
    <xsl:template match="/">
     <ul
       <xsl:for-each select="$newsYear">
        <li>
          <href="{umbraco.library:NiceUrl(@id)}">  
            <xsl:value-of select="@nodeName"/>
          </a>
        </li>  
      </xsl:for-each>
      </ul>
    </xsl:template>

    My xslt has been stripped back

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 06, 2012 @ 15:22
    Chriztian Steinmeier
    0

    Hi Martin,

    The XPaths you've supplied does in fact select "everything around me", so that's probably why it happens.

    Start by creating a siteRoot variable after currentPage - this one should go up to the level of your site's Home node (usually @level=1):

    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />

    Now, create another variable that selects from the $siteRoot variable, grabbing the "year" nodes, e.g.:

    <xsl:variable name="years" select="$siteRoot/*[@nodeName = 'News']/*[@isDoc]" />

    (Remember to tweak the path - here, I'm guessing there's a node called 'News' and that the children of that are the Year folders.)

    Now you're ready to start the for-each:

    <xsl:for-each select="$years">
       ...
    </xsl:for-each>

     

    /Chriztian

  • Martin 278 posts 662 karma points
    Feb 06, 2012 @ 16:10
    Martin
    0

    Thanks Christian, 

    Im getting the year and month output, but the months are repeating under each of the years. 

     

    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    <xsl:variable name="years" select="$siteRoot/*[@nodeName = 'News Archive']/*[@isDoc]" />
    <xsl:variable name="months" select="$siteRoot/*[@nodeName = 'News Archive']/DateFolder/*[@isDoc]" />
    <xsl:variable name="newsItem" select="$siteRoot/*[@nodeName = 'News Archive']/DateFolder/DateFolder/*[@isDoc]" />  

        <xsl:template match="/">
     <ul
       <xsl:for-each select="$years">
        <li class="years"
           <xsl:value-of select="@nodeName"/>
           <ul
             <xsl:for-each select="$months">
              <li class="months">
                <href="{umbraco.library:NiceUrl(@id)}">  
                  <xsl:value-of select="@nodeName"/>
                </a>
              </li>  
            </xsl:for-each>
           </ul>
        </li>  
      </xsl:for-each>
     </ul>
    </xsl:template>

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 06, 2012 @ 16:18
    Chriztian Steinmeier
    1

    Hi Martin,

    Yes - see, once you've got the years, you automatically have the rest. Just dig in:

    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    <xsl:variable name="years" select="$siteRoot/*[@nodeName = 'News Archive']/*[@isDoc]" />
    
    <xsl:template match="/">
        <ul> 
            <xsl:for-each select="$years">
                <li class="years"> 
                    <xsl:value-of select="@nodeName"/>
                    <ul> 
                        <xsl:for-each select="*[@isDoc]"><!-- Children of the current year are months, right? -->
                            <li class="months">
                                <a href="{umbraco.library:NiceUrl(@id)}">  
                                    <xsl:value-of select="@nodeName"/>
                                </a>
                            </li>  
                        </xsl:for-each>
                    </ul>
                </li>  
            </xsl:for-each>
        </ul>
    </xsl:template>

    /Chriztian

  • Martin 278 posts 662 karma points
    Feb 06, 2012 @ 16:33
    Martin
    0

    Ah, Thanks Chriztian,

    I see it now.

    Thanks again.

  • Martin 278 posts 662 karma points
    Feb 07, 2012 @ 10:44
    Martin
    0

    Hi Chriztian,

    The DateFolders package im using automatically names the folders as numbers.

    Is there any way to change the node name into a months?

     

    Thanks

    Martin

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 07, 2012 @ 10:56
    Chriztian Steinmeier
    0

    Hi Martin,

    You just mean to display the monthname, right? (As opposed to renaming the actual folders in the backoffice).

    Do you have multiple languages in the site so you need to supply the names in more than one language?

    /Chriztian

  • Martin 278 posts 662 karma points
    Feb 07, 2012 @ 11:00
    Martin
    0

    Hi, 

    Im fine with just renaming the months as the appear on the site.

    Its only in English.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 07, 2012 @ 11:21
    Chriztian Steinmeier
    1

    Hi Martin,

    Then I'd just create a lookup variable with the names and pick from that one using the @nodeName index - like this:

    <!-- Lookup variable -->
    <xsl:variable name="monthNamesProxy">
        <month>January</month>
        <month>February</month>
        <month>March</month>
        <month>April</month>
        <month>May</month>
        <month>June</month>
        <month>July</month>
        <month>August</month>
        <month>September</month>
        <month>November</month>
        <month>December</month>
    </xsl:variable>
    <xsl:variable name="monthNames" select="msxsl:node-set($monthNamesProxy)/month" />
    
    <!-- Generic template to output monthname -->
    <xsl:template match="*" mode="monthname">
        <xsl:value-of select="$monthNames[position() = current()/@nodeName]" />
    </xsl:template>
    
    ...
    
    <xsl:for-each select="*[@isDoc]"><!-- Children of the current year are months, right? -->
        <li class="months">
            <a href="{umbraco.library:NiceUrl(@id)}">
    <!-- Output monthname instead of @nodeName --> 
                <xsl:apply-templates select="." mode="monthname" />
            </a>
        </li>  
    </xsl:for-each>
    

    /Chriztian 

  • Martin 278 posts 662 karma points
    Feb 07, 2012 @ 11:52
    Martin
    0

    Thanks Chriztian.

    There was a typo with the "msxsl" that threw me for a second.

    But thanks again.

  • Martin 278 posts 662 karma points
    Feb 07, 2012 @ 15:43
    Martin
    0

    Sorry, ive got a sort issue with my DateFolders now.

    I have a datepicker field attached to my NewsItem doctype. This date picker called startDate is used to override the createDate and places the news items in a chosen folder.

    Im struggling to sort my Datefolders based on the the startDate field.

    Any help would be grateful.

    Martin

     

    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    <xsl:variable name="years" select="$siteRoot/*[@nodeName = 'News Archive']/*[@isDoc]" />


    <!-- Lookup variable -->
    <xsl:variable name="monthNamesProxy">
      <month>January</month>
      <month>February</month>
      <month>March</month>
      <month>April</month>
      <month>May</month>
      <month>June</month>
      <month>July</month>
      <month>August</month>
      <month>September</month>
      <month>November</month>
      <month>December</month>
    </xsl:variable>
    <xsl:variable name="monthNames" select="msxml:node-set($monthNamesProxy)/month" />

    <!-- Generic template to output monthname -->
    <xsl:template match="*" mode="monthname">
      <xsl:value-of select="$monthNames[position() = current()/@nodeName]" />
    </xsl:template>  
        
    <xsl:template match="/"
      <div class="four panels alpha">
        <h4>../News Archive</h4>  
        <ul class="archive"
        <xsl:for-each select="$years">
          <xsl:sort select="$years" data-type="number"  order="descending"/>
          <li class="years"
            <xsl:value-of select="@nodeName"/>
            <ul>
              <xsl:for-each select="*[@isDoc]"><!-- Children of the current year are months, right? -->
              <li class="months">
                <href="{umbraco.library:NiceUrl(@id)}">
                <!-- Output monthname instead of @nodeName --> 
                <xsl:apply-templates select="." mode="monthname" /> |          
                </a>
              </li>  
              </xsl:for-each>
            </ul>
          </li>  
          </xsl:for-each>
        </ul>
      </div>  
    </xsl:template> 
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 07, 2012 @ 17:10
    Chriztian Steinmeier
    0

    Hi Martin,

    What do you need to sort? Isn't that what the DateFolder package does for you?

    Anyway - you can use this sort instruction inside a for-each to sort on the newsDate property of whichever nodes are being iterated:

    <xsl:sort select="newsDate" data-type="text" order="descending" />

     

    /Chriztian

    PS: You should consider creating new threads - it can be hard to find solutions to specific topics, if some of them are "hidden" in the comments of another topic.

Please Sign in or register to post replies

Write your reply to:

Draft