how to grap first 3 nodes when position() not starting at 1?
Hey umbraco GURUS :) i am grabbing all events in the tree that are happenign AFTER today... but i want to only show the first 3... I usually use a test based on position(), but my position ids start at 4 in this particular case...
yeah, but i don't really know the postition offset... i really need a way to re-seed the position() i think nodeset is what i want, but not sure how to implement...
here is my code snippet
<xsl:variable name="numToShow"
select="number($currentPage/howManyEventItemsToList)"/> <xsl:variable name="nodes" select="umbraco.library:GetXmlAll()//* [name() =
$documentTypeAlias and string(umbracoNaviHide) != '1']"/> <ul id="newsNewsList"> <xsl:for-each
select="position()<=
$numToShow and umbraco.library:GetXmlAll()//* [name() =
$documentTypeAlias and string(umbracoNaviHide) != '1']"> <xsl:sort select="eventStartDate" order="ascending"/>
i am basically letting the client specify how many events they want to show... then grabbing all events... then showing the top 3... but the postition is based on the entire list... not the ones that are past the date of today... do i just need to move my date logic into my for-each?
It can be done your way, but you'd need to iterate your events first, build up a string containing events which should be shown (ie after today) and then use split to iterate the list again (think of how xslt search is doing it...)
But, anyway, I'd move the logic into the variable 'nodes'
um, disregard that code above... that was some bad copy and paste - DOH! total blonde moment there...
anyway, this appears to work better now...
<!-- Input the documenttype you want here
--> <xsl:variable name="documentTypeAlias"
select="string('EventItem')"/> <xsl:variable name="today" select="Exslt.ExsltDatesAndTimes:date()"/>
<xsl:template
match="/"> <h3>Upcoming
Events</h3> <!-- The fun starts here --> <xsl:variable name="numToShow"
select="number($currentPage/howManyEventItemsToList)"/> <xsl:variable name="nodes" select="umbraco.library:GetXmlAll()//* [name() =
$documentTypeAlias and string(umbracoNaviHide) != '1']"/> <ul id="newsNewsList"> <xsl:for-each
select="umbraco.library:GetXmlAll()//*
[name() = $documentTypeAlias and string(umbracoNaviHide) !=
'1'][umbraco.library:DateGreaterThan(eventStartDate, $today)]"> <xsl:sort select="eventStartDate" order="ascending"/>
The key is to return only events that have dates that haven't yet expired. Umbraco provides a really handy "umbraco.library:DateGreaterThanOrEqualToday". Include that in the predicate for your variable.
Something like (I typed in the forum, watch for silly errors)...
<xsl:variable name="nodes" select="umbraco.library:GetXmlAll()//* [
name() = $documentTypeAlias
and string(umbracoNaviHide) != '1'
and umbraco.library:DateGreaterThanOrEqualToday($eventStartDate)
]" />
Then you use position() <= $numToShow in your for-each and you're done.
how to grap first 3 nodes when position() not starting at 1?
Hey umbraco GURUS :) i am grabbing all events in the tree that are happenign AFTER today... but i want to only show the first 3... I usually use a test based on position(), but my position ids start at 4 in this particular case...
how do i count those?
Can't you include the AFTER clause in the for-each to filter out these that shouldn't be in the list and then start from 1 using position()?
Cheers,
/Dirk
Do you know what the offset position is? Can you get it into a variable? If so, just do some simple math?
Matt
yeah, but i don't really know the postition offset... i really need a way to re-seed the position() i think nodeset is what i want, but not sure how to implement...
here is my code snippet
i am basically letting the client specify how many events they want to show... then grabbing all events... then showing the top 3... but the postition is based on the entire list... not the ones that are past the date of today... do i just need to move my date logic into my for-each?
It can be done your way, but you'd need to iterate your events first, build up a string containing events which should be shown (ie after today) and then use split to iterate the list again (think of how xslt search is doing it...)
But, anyway, I'd move the logic into the variable 'nodes'
Cheers,
/Dirk
um, disregard that code above... that was some bad copy and paste - DOH! total blonde moment there...
anyway, this appears to work better now...
The key is to return only events that have dates that haven't yet expired. Umbraco provides a really handy "umbraco.library:DateGreaterThanOrEqualToday". Include that in the predicate for your variable.
Something like (I typed in the forum, watch for silly errors)...
<xsl:variable name="nodes" select="umbraco.library:GetXmlAll()//* [ name() = $documentTypeAlias and string(umbracoNaviHide) != '1' and umbraco.library:DateGreaterThanOrEqualToday($eventStartDate) ]" />
Then you use position() <= $numToShow in your for-each and you're done.
cheers,
doug.
ah, i was using dategreater than, but i had NO IDEA there was a built in greater than today - BRILLIANT!
Thanks for all the help guys! H5YR!
To complete the picture,
cheers,
doug.
is working on a reply...