As you see it's basically a two column layout and each one holds 3 news. So, i get the last 6 nodes of news through XSLT 6 xPath, but... how do I tell them to put the latest one on the top of the left column, the next one on the top of the left one, the next one secnd on the right one....
The only thing I have come up to till now is to put it in separate lines instead than in a for-each loop for the nodes, but I also don't know still ho to tell XSLT "select the next node from the last one you selected" unless it keeps an index forthe last position you tok or smething like that.
I'm not asking for code of course, just if someone could point me to any article or something where discretional placing through XSLT is achieved.
I was just
guessing about the position() function as I am looking at the ListNewsEvents.xslt from an Umbraco package. The things is that we would like to have the first one on the left column, the second one on the right column, the thir on the left...
1 ------------- 2
3 ------------- 4
5 ------------- 6
If I'm not mistaken, working the position() function like that would leave it:
1 ------------- 4
2 ------------- 5
3 ------------- 6
We would like that as some news are "the most important ones" and when there is more than one of those, they should be at the top of the columns as they are displayed more eye-catching.
Sounds like your are pretty much going to need to break it up into multiple queries, storing results into variables, then do a final render at the end.
I'd probably start by pulling back all your news items, sorting them so that the "most important" ones appear at the top (depending how you define this, this might also have to be broken up into 2 queries to pull back important ones, then non important ones and merging them).
At this point you should have a var holding all the nodes you need in the right order. I'd then do 2 queries for each side and within your for-each, use a filter to only pull out odd/even entries
[position() mod 2 = 0]
or
[position() mod 2 = 1]
This should give you results in the order, and in the layout you need.
1 ------------- 2 3 ------------- 4 5 ------------- 6 if you want this order why not then just float all your items left, and have have a containing div is only 2 floats wide, meaning that your 3rd will drop to the next line? <div class="newsitems"> <div class="news"> <h3>my news 1</h3> <p>Lorem Ipsum</p> </div> <div class="news">
<h3>my news 1</h3>
<p>Lorem Ipsum</p> </div> <div class="news">
<h3>my news 1</h3>
<p>Lorem Ipsum</p> </div> <div class="news">
<h3>my news 1</h3>
<p>Lorem Ipsum</p> </div> <div class="news">
<h3>my news 1</h3>
<p>Lorem Ipsum</p> </div> <div class="news">
<h3>my news 1</h3>
<p>Lorem Ipsum</p> </div> </div>
.newsitems{width:600px} .news{float:left; width:300px;} there you go. a fake 2 column layout.
As wolulcmit suggests - CSS is the better option, it keeps a separation between the structure/mark-up and the design.
If you do need to have the news items in separate <div> elements/structures, then following on from Matt's/Niels' suggestions of using position(), you can lose the <xsl:for-each> and use <xsl:template>, like so...
This forum is really amazing in terms of helping each other. Hope I can give something back as soon as possible.
I am not at home now so can't try anything right now, but I will have a look at everything later and post back with my thoughts. I'm using Umbraco 4.5 by the way, in case it's of help.
Busy days so I haven't been able to get back to you sooner. First of all, thanks a lot to everyone who has taken the time to write. Wish I had karma to give you all!
I finally chose to update my layout through CSS to float all the news left while creating two columns as wolulcmit suggested. I then created a "List sub pages by type" macro and put Lee Kelleher's code on it resulting in:
Placing nodes in different floating divs
Hello all,
I'm building a sports news site. The section I'm trying to get done now looks like this in HTML
[code]
<div class="new">
<img class="new_country" src="images/content/countries_titles/usa.gif">
<img class="new_flag" src="images/content/flags/usa.jpg">
<h1>New Title</h1>
<p>
<span class="new_date">TheDate</span>SomeText<br />
<span class="new_readmore">Read more...</span>
</p>
</div>
<!-- here it goes another two "new" divs -->
</div>
<div class="new">
<img class="new_country" src="images/content/countries_titles/usa.gif">
<img class="new_flag" src="images/content/flags/usa.jpg">
<h1>New Title</h1>
<p>
<span class="new_date">TheDate</span>SomeText<br />
<span class="new_readmore">Read more...</span>
</p>
</div>
<!-- here it goes another two "new" divs -->
</div>
[/code]
As you see it's basically a two column layout and each one holds 3 news. So, i get the last 6 nodes of news through XSLT 6 xPath, but... how do I tell them to put the latest one on the top of the left column, the next one on the top of the left one, the next one secnd on the right one....
The only thing I have come up to till now is to put it in separate lines instead than in a for-each loop for the nodes, but I also don't know still ho to tell XSLT "select the next node from the last one you selected" unless it keeps an index forthe last position you tok or smething like that.
I'm not asking for code of course, just if someone could point me to any article or something where discretional placing through XSLT is achieved.
Thank you so much!
Sorry it doesn't le me edit to put the code well. When I try the forum returns this error:
Anyway, although it's not very relevant, the properly formatted HTML code is this:
Thanks!
do something like this within your for-each statement:
Hello wolulcmit and thanks for answering.
I was just guessing about the position() function as I am looking at the ListNewsEvents.xslt from an Umbraco package. The things is that we would like to have the first one on the left column, the second one on the right column, the thir on the left...
1 ------------- 2
3 ------------- 4
5 ------------- 6
If I'm not mistaken, working the position() function like that would leave it:
1 ------------- 4
2 ------------- 5
3 ------------- 6
We would like that as some news are "the most important ones" and when there is more than one of those, they should be at the top of the columns as they are displayed more eye-catching.
Any idea about it? Thanks!
Hey Jacob,
Sounds like your are pretty much going to need to break it up into multiple queries, storing results into variables, then do a final render at the end.
I'd probably start by pulling back all your news items, sorting them so that the "most important" ones appear at the top (depending how you define this, this might also have to be broken up into 2 queries to pull back important ones, then non important ones and merging them).
At this point you should have a var holding all the nodes you need in the right order. I'd then do 2 queries for each side and within your for-each, use a filter to only pull out odd/even entries
or
This should give you results in the order, and in the layout you need.
Matt
Hey,
So you want the odd numbers on the left and the even on te right?
<!-- left news items "odd" -->
<xsl:for-each select="$newsItems [position() mod 2 = 1]">
<!-- print news stuff -->
</xsl:for-each>
<!-- Right news items "even" -->
<xsl:for-each select="$newsItems [position() mod 2 = 0]">
<!-- print news stuff -->
</xsl:for-each>
1 ------------- 2
3 ------------- 4
5 ------------- 6
if you want this order why not then just float all your items left, and have have a containing div is only 2 floats wide, meaning that your 3rd will drop to the next line?
<div class="newsitems">
<div class="news">
<h3>my news 1</h3>
<p>Lorem Ipsum</p>
</div>
<div class="news">
<h3>my news 1</h3>
<p>Lorem Ipsum</p>
</div>
<div class="news">
<h3>my news 1</h3>
<p>Lorem Ipsum</p>
</div>
<div class="news">
<h3>my news 1</h3>
<p>Lorem Ipsum</p>
</div>
<div class="news">
<h3>my news 1</h3>
<p>Lorem Ipsum</p>
</div>
<div class="news">
<h3>my news 1</h3>
<p>Lorem Ipsum</p>
</div>
</div>
.newsitems{width:600px}
.news{float:left; width:300px;}
there you go. a fake 2 column layout.
HI Jacobo,
As wolulcmit suggests - CSS is the better option, it keeps a separation between the structure/mark-up and the design.
If you do need to have the news items in separate <div> elements/structures, then following on from Matt's/Niels' suggestions of using position(), you can lose the <xsl:for-each> and use <xsl:template>, like so...
Not sure which version of Umbraco you are using, whether its the new or old XML schema, but just add your XPath to the "newsItems" variable.
Then you can have a separate <xsl:template> to handle the news item nodes...
Again, I don't know much about your doc-type properties - just guessing that the content is called 'bodyText'.
Cheers, Lee.
Thank you for all guys,
This forum is really amazing in terms of helping each other. Hope I can give something back as soon as possible.
I am not at home now so can't try anything right now, but I will have a look at everything later and post back with my thoughts. I'm using Umbraco 4.5 by the way, in case it's of help.
Really, really thank you all! Cheers!
Hello all,
Busy days so I haven't been able to get back to you sooner. First of all, thanks a lot to everyone who has taken the time to write. Wish I had karma to give you all!
I finally chose to update my layout through CSS to float all the news left while creating two columns as wolulcmit suggested. I then created a "List sub pages by type" macro and put Lee Kelleher's code on it resulting in:
I now only have to limit that to get the first six news which have the "Important" attribute set to yes, but I guess that will be easy to do.
Really... thank you all, this is a great forum. The beginnings are hard but all is fitting pretty well thanks to you all. Cheers!
is working on a reply...