List of two containing two different document types
Hi there,
I'm trying to make a list that contains news items and new gallaries - ordered by the date they were created. I've managed to loop through the two seperatly and call the approprate templates, but i'm struggling to get them both in the same ordered list.
I've also trying to loop through everything and just filter on the alais, but I cant get that to work either. Can anyone suggest a way to do this? Many thanks.
I'm having a bit of trouble working out how to get this to just show the top X number of blogs/gallery albums now that i'm using <xsl:apply-templates rather than <xsl:for-each . Im trying to do something like this:
<xsl:template match="/"> <xsl:if test="position() < $numberOfPosts"> <!-- Go through them all sorted by created date --> <xsl:apply-templates select="$newsItems | $galleryItems"> <xsl:sort select="@postDate" data-type="text" order="descending" /> </xsl:apply-templates> </xsl:if> </xsl:template>
but position() doesnt seem to have a value. Any ideas? Many thanks.
The trick is to know that position() always refers to the "current node's position within the current node-set" - when using apply-templates, the current node-set is all the nodes you select in the apply-templates's select attribute (same as when you use for-each). This means that every template that apply-templates instantiates will have its own unique position() within the combined set - so you can perform the test within the individual templates to achieve the same result, e.g.:
List of two containing two different document types
Hi there,
I'm trying to make a list that contains news items and new gallaries - ordered by the date they were created. I've managed to loop through the two seperatly and call the approprate templates, but i'm struggling to get them both in the same ordered list.
This is the for-each loop for the news:
<xsl:for-each select="$currentPage/ancestor-or-self::umbBlog//umbBlogPost">
and this is for the gallery album:
<xsl:for-each select="$currentPage//umbGalleryAlbum">
I've been trying to do something like this:
<xsl:for-each select="$currentPage/*[ancestor-or-self::umbBlog//umbBlogPost|//umbGalleryAlbum]">
But I can't get it to work.
I've also trying to loop through everything and just filter on the alais, but I cant get that to work either. Can anyone suggest a way to do this? Many thanks.
Hi Luke,
Here's how I'd usually approach this - should be easy to modify:
/Chriztian
Wow, that's fantasitc thanks Chriztian! I shall try this and post how I get on. Thanks
Wow, that's fantasitc thanks Chriztian it works perfectly first time! Thanks, been trying to crack this all day!
I'm having a bit of trouble working out how to get this to just show the top X number of blogs/gallery albums now that i'm using <xsl:apply-templates rather than <xsl:for-each . Im trying to do something like this:
<xsl:template match="/">
<xsl:if test="position() < $numberOfPosts">
<!-- Go through them all sorted by created date -->
<xsl:apply-templates select="$newsItems | $galleryItems">
<xsl:sort select="@postDate" data-type="text" order="descending" />
</xsl:apply-templates>
</xsl:if>
</xsl:template>
but position() doesnt seem to have a value. Any ideas? Many thanks.
Hi Luke,
The trick is to know that position() always refers to the "current node's position within the current node-set" - when using apply-templates, the current node-set is all the nodes you select in the apply-templates's select attribute (same as when you use for-each). This means that every template that apply-templates instantiates will have its own unique position() within the combined set - so you can perform the test within the individual templates to achieve the same result, e.g.:
/Chriztian
Ah. I see. And it works like a charm. Thanks again!
is working on a reply...