And something similar for Events. However what I would also like to do is list the News Items and Events on the Home page. I am guessing my XSLT for the Home page will be very similar, except with a different select attribute on the xsl:for-each element. But I don't know what I should use!
Any help is greatly appreciated. I apologize if this has been addressed already but I wasn't quite sure what to search on for this topic.
And now to the examples of how you can achieve your goal.
By using a XPATH expression like this ancestor-or-self::node you can go all the way back to the root node of the site and then decide, what type of nodes you want to list on a given page.
A snippet could look like this:
<xsl:for-each select="$currentPage/ancestor-or-self::node//node[@nodeTypeAlias = 'NewsItem']"> <!--- Your code here -->
</xsl:for-each>
But please note that using the double forward slashes "//" in the above expression could lower the performance as far as I know.
Another approach could be to use the extension "GetXmlNodeById", which is a part of the umbraco.library.
Then you could for instance do something like this:
in the above sample 1090 is a fictive id and you off course need to replace it with the id of your news section.
Of course it's not a good idea to hardcode id's so you should probably make use of a content picker property on your "home" node, so you can select the NewsSource from the content tree and then get the value by writing <xsl:variable name="newsSource select="$currentPage/data [@alias ='yourcontentpickeralias'] />.
It's possible to do it in even more ways but I think this should be enough to get you started - I hope that it all makes sense, otherwise just ask! :-)
Parsing nodes NOT from currentPage
Hi everyone,
I'm still new to XSL so please have patience. What I am trying to do is set up my content like this:
- Home
- News
-- News Item 1
-- News Item 2
-- News Item 3
- Event List
-- Event 1
-- Event 2
I am able to easily display the News Item nodes on the News page using the following transform:
And something similar for Events. However what I would also like to do is list the News Items and Events on the Home page. I am guessing my XSLT for the Home page will be very similar, except with a different select attribute on the xsl:for-each element. But I don't know what I should use!
Any help is greatly appreciated. I apologize if this has been addressed already but I wasn't quite sure what to search on for this topic.
Hi Alex
This can be achieved in different ways.
If you are completely new to XSLT I will recommend that you read http://www.w3schools.com/xsl/default.asp and http://www.w3schools.com/xpath/xpath_functions.asp. Please note that some of the version 2 stuff is not yet usable with .NET.
I also think you should have a look at umbraco.tv where there are some free samples that could probably get you going. And finally it might be worth reading a bit about axes in XPATH here http://umbraco.org/documentation/books/xslt-basics/xpath-axes-and-their-shortcuts
And now to the examples of how you can achieve your goal.
By using a XPATH expression like this ancestor-or-self::node you can go all the way back to the root node of the site and then decide, what type of nodes you want to list on a given page.
A snippet could look like this:
<xsl:for-each select="$currentPage/ancestor-or-self::node//node[@nodeTypeAlias = 'NewsItem']">
<!--- Your code here -->
</xsl:for-each>
But please note that using the double forward slashes "//" in the above expression could lower the performance as far as I know.
Another approach could be to use the extension "GetXmlNodeById", which is a part of the umbraco.library.
Then you could for instance do something like this:
<xsl:variable name="newsSource" select="umbraco.library:GetXmlNodeById('1090')" />
<xsl:for-each select="$newsSource/node">
<!-- your code here -->
</xsl:for-each>
in the above sample 1090 is a fictive id and you off course need to replace it with the id of your news section.
Of course it's not a good idea to hardcode id's so you should probably make use of a content picker property on your "home" node, so you can select the NewsSource from the content tree and then get the value by writing <xsl:variable name="newsSource select="$currentPage/data [@alias ='yourcontentpickeralias'] />.
It's possible to do it in even more ways but I think this should be enough to get you started - I hope that it all makes sense, otherwise just ask! :-)
/Jan
is working on a reply...