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.
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.
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:
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.
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>
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?
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! :)
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.
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
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
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.
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>
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"
Assuming that your News Release pages are based on a doctype called NewsRelease, you could render the News Archives page witht he following macro:
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?
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:
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.
is working on a reply...