I am currently attempting in XSLT to generate a list of unique year values from a nodeset of news items. I have always had a lot of success using the so-called Meunchian method (generate-id()) for this type of thing but for some reason, in this case, several year values are missing from the list, even though there are definitely items which have those (missing) values. Result is 2014 | 2010 | 2009 but should in reality include 2013, 2012, and 2011 as well. Can anyone tell what I am doing wrong here? I would appreciate the help as I am stumped!
The only things I see (without having tried it or anything like that) are these two:
Your key is indexing more nodes than you probably think it is ("" in the match attribute will index all properties as well - but with an empty string as the value - better to use "[@isDoc]" to only match document nodes)
You're using 0, 5 to select the year - strings in XSLT are 1-based, so you should be using 1, 4 instead (makes more sense too, right?)
Both of these shouldn't really affect the results, but I know XSLT processors vary, so might be something there...
I'll try to test your code and see what I come up with though...
Thanks as usual for your always-timely reply, Chriztian. As for the substring 1,4 -- you are absolutely right -- yes, makes much better sense. I've modified that now. No difference in the output. As for the indexing key, although I could certainly match only documents (match="*[@isDoc]"), remember, our problem is not that we are getting too many results, but that we aren't getting enough! Matching against *[@isDoc] yields the same result -- missing 2013, 2012, and 2011, even though all those years are well-represented in the database. All children are the same document type and use the Date Picker field, all dates are populated, and all pages are published.
I totally agree with your thoughts about the key - only reason I mention it is for those copying the basics from here, then modifying the use attribute, and suddenly getting wildly crazy results x)
So I've been testing this with some made-up data, but everything works as expected, so I have another idea, which I'm about to bet you a beer on...:
My guess is that you've got other types of nodes using the datePosted property... - remember, the Muenchian trick compares a node in a set of nodes with the first node returned from the key - Now, the key returns nodes from all over the entire structure, so let's say you have a Textpage somewhere before the "Press Releases" node, and that Textpage has a datePosted property with the value 2013-12-11... ? Exactly — you won't get that value in the loop.
If that's it, we'll need to modify the key to specifically index only nodes below the "Press Releases" node (or some other way of identifying them).
Needed to be much more selective with the nodes matched for comparison.
Dang -- that's tricky! Your discovery has gained me a better understanding of the xsl:key concept, thiough, so I don't think I'll have this problem again! CHEERS, Chriztian!
List of Unique Years - generate-id() Problems
Hi,
I am currently attempting in XSLT to generate a list of unique year values from a nodeset of news items. I have always had a lot of success using the so-called Meunchian method (generate-id()) for this type of thing but for some reason, in this case, several year values are missing from the list, even though there are definitely items which have those (missing) values. Result is 2014 | 2010 | 2009 but should in reality include 2013, 2012, and 2011 as well. Can anyone tell what I am doing wrong here? I would appreciate the help as I am stumped!
Thanks,
Garrett
Hi Garrett,
The only things I see (without having tried it or anything like that) are these two:
match
attribute will index all properties as well - but with an empty string as the value - better to use "[@isDoc]" to only match document nodes)Both of these shouldn't really affect the results, but I know XSLT processors vary, so might be something there...
I'll try to test your code and see what I come up with though...
/Chriztian
Thanks as usual for your always-timely reply, Chriztian. As for the substring 1,4 -- you are absolutely right -- yes, makes much better sense. I've modified that now. No difference in the output. As for the indexing key, although I could certainly match only documents (match="*[@isDoc]"), remember, our problem is not that we are getting too many results, but that we aren't getting enough! Matching against *[@isDoc] yields the same result -- missing 2013, 2012, and 2011, even though all those years are well-represented in the database. All children are the same document type and use the Date Picker field, all dates are populated, and all pages are published.
//Garrett
Hi again - you're welcome :)
I totally agree with your thoughts about the key - only reason I mention it is for those copying the basics from here, then modifying the use attribute, and suddenly getting wildly crazy results x)
So I've been testing this with some made-up data, but everything works as expected, so I have another idea, which I'm about to bet you a beer on...:
My guess is that you've got other types of nodes using the datePosted property... - remember, the Muenchian trick compares a node in a set of nodes with the first node returned from the key - Now, the key returns nodes from all over the entire structure, so let's say you have a Textpage somewhere before the "Press Releases" node, and that Textpage has a datePosted property with the value 2013-12-11... ? Exactly — you won't get that value in the loop.
If that's it, we'll need to modify the key to specifically index only nodes below the "Press Releases" node (or some other way of identifying them).
Cheers,
/Chriztian
That was it ;)
Needed to be much more selective with the nodes matched for comparison.
Dang -- that's tricky! Your discovery has gained me a better understanding of the xsl:key concept, thiough, so I don't think I'll have this problem again! CHEERS, Chriztian!
//Garrett
is working on a reply...