Copied to clipboard

Flag this post as spam?

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


  • Dana 10 posts 30 karma points
    Nov 02, 2011 @ 22:35
    Dana
    0

    news release archive

    I'm relatively new to xslt, and I'm looking for help doing something I think (but am not certain) is farily simple.

    On my site I have a bunch of press releases, each an individual piece of content, sorted by calendar year.

    I'd like to automatically populate a separate archive page with a list of all press releases, or perhaps separate lists for each folder.

    I assume this can be achieved with an xslt maco, and the answer is probably somewhere in the forum already, but I can't find anything that really matches my goal.

    If anyone posts xslt, can you comment it so I can learn what each bit in the code is doing? I'd really like to be able to create these macros myself at some point.

    Thanks!
    Dana

  • Rich Green 2246 posts 4008 karma points
    Nov 02, 2011 @ 23:21
    Rich Green
    0

    Hey Dana,

    The concept I would use would be to keep the same structure you have and add a 'Archive' property to your Press Releases DocType of the type "True/False".

    Then when you're pulling out your current Press releases you can check that it's not 'Archived' and for your archive page you pull all the Press Releases where Archived = true.

    Make sense?

    Rich

  • Dana 10 posts 30 karma points
    Nov 03, 2011 @ 21:18
    Dana
    0

    That does make sense, and might be easier than what I was originally planning. However, since I'm not familiar with xslt syntax, I have no idea how to create a macro that would pull all child pages marked "true."

    Visually here's what my file structure looks like:

    [] News Archives
         [] News 2011
              [] News Release 01
              [] News Release 02
              [] News Release 03
         [] News 2010
              [] News Release 01
              [] News Release 02
              [] News Release 03

    So I want to automatically populate the News Archives page with links to all the news releases, but not to the News 2011 and News 2010 nodes, as those are just placeholders and have no content.

    I'm thinking a simple subnavigation macro would work here, but I haven't quite figured out how to modify what I've seen in the forum to something that works for me.

  • Anthony pj 40 posts 63 karma points
    Nov 03, 2011 @ 22:36
    Anthony pj
    0

    two choices here

    <xsl:param name="currentPage"/>


    <xsl:variable name="documentTypeAlias" select="string('ProductReview')"/>

    <xsl:template match="/">


    <ul>
    <xsl:for-each select="$currentPage/descendant::* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        a>
      li>
    xsl:for-each>
    ul>

    xsl:template>

    xsl:stylesheet>

     

    or

    <xsl:param name="currentPage"/>

    <xsl:variable name="level" select="3"/>

    <xsl:template match="/">


    <ul>
    <xsl:for-each select="$currentPage/descendant::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        a>
      li>
    xsl:for-each>
    ul>

    xsl:template>


  • Anthony pj 40 posts 63 karma points
    Nov 03, 2011 @ 22:42
    Anthony pj
    0

    Sorry incase it is not obvious in first example

    <xsl:variable name="documentTypeAlias" select="string('ProductReview')"/>

    would be the document type alias of News Release

    and

    string(umbracoNaviHide) != '1'

    would change to read what ever variable you are using to mark your child page "true"

  • Dan Okkels Brendstrup 101 posts 197 karma points
    Nov 09, 2011 @ 10:43
    Dan Okkels Brendstrup
    0

    Assuming that your News Release pages are based on a doctype called NewsRelease, you could render the News Archives page witht he following macro:

    <!--This is the macro that renderes the News Arhives page-->
    <xsl:template match="/">
      <ul>
        <!--Apply templates to all (unhidden) NewsRelease documents anywhere below the current page-->
        <xsl:apply-templates select="$currentPage//NewsRelease[umbracoNaviHide != 1]">
          <!--Sort by last updated in case the node order in Umbraco is non-chronological-->
          <xsl:sort select="@updateDate" order="descending"/>
        </xsl:apply-templates>
      </ul>
    </xsl:template>
     
    <xsl:template match="NewsRelease">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:template>
  • Dana 10 posts 30 karma points
    Nov 17, 2011 @ 23:58
    Dana
    0

    Thanks everyone for your answers. I'll probably try to implement one of these suggestions at some point. My temporary fix was to use an xslt intended for subnavigation and modify it slightly, then pull it in at the page level.

    My only question now is where can I find a nice robust xslt tutorial so I can make more substantial modifications to existing files and eventually start writing my own?

     

  • Dan Okkels Brendstrup 101 posts 197 karma points
    Nov 18, 2011 @ 12:52
    Dan Okkels Brendstrup
    1

    Hi Dana,

    Great that you're up for diving into XSLT. Mozilla's Developer Network has a good XSLT reference, and I've also found that IBM developerWorks has some very good tutorials, including these:

    And for a basic understanding of XPath axes, Chriztian has built a good visualizer. And this forum is of course a good place to ask questions anytime! :)
  • Dana 10 posts 30 karma points
    Nov 18, 2011 @ 22:45
    Dana
    0

    Thank you! Thank you!

    I'm really interested in being a well-rounded developer, rather than just someone who just writes HTML and CSS. I will defintely continue to direct questions to the forum!

    I'm learning Python too, so I might throw questions at the forum on that topic as well.

Please Sign in or register to post replies

Write your reply to:

Draft