I have an XSLT file that lists the month and Press Release nodes under each Year node, and I am looking for a way to display the full name of the month indicated in each month node's nodeName. For example, for 07, I would like to display "July". The createDate and updateDate of the Month nodes aren't necessarily going to match what I want to display; I want to go by the nodeName. What's the best way to convert the 'MM' format text into a full month name?
Thanks for the reply. That looks like a good way to do it, I'll have to try it out. I discovered my own way to do it as well, and it's a lot simpler, but it seems like it might be bad practice:
Essentially, I am just adding in phony info to make the 'MM' string into a proper date string, and then using FormatDateTime to display only the month. It works, and it's very simple, but there might be a possibility of the phony info getting displayed somehow. Should I avoid doing this?
I could make it a little safer to use by using the document's creation date as a starting point, then overriding the month part, but that hurts its simplicity.
Your way is another good way of doing it - but you should be very careful with the prMonthName variable though (whitespace etc.) - best way to create it would be like this:
This way, you're not leaving anything up the processor, regarding which whitespace nodes are significant and should or should not be included. (Any extra whitespace would throw an exception when sent to the FormatDateTime() extension.)
The reason I use the other method is that more often than not, the design (or the client) needs some of the monthnames abbreviated - e.g.: "May", "June" and "July" are fine, but the others should be "Jan.", "Feb." etc.
One other benefit to yours, however, is that it will automatically output the monthnames in the chosen Culture for the node (e.g., if you're in a multilingual site)
Get month name from 'MM' format string?
I have a Press Releases section with a node tree in the following format:
2012
01
Press Release 1
03
Press Release 2
Press Release 3
05
2011
03
Press Release 4
07
Press Release 5
I have an XSLT file that lists the month and Press Release nodes under each Year node, and I am looking for a way to display the full name of the month indicated in each month node's nodeName. For example, for 07, I would like to display "July". The createDate and updateDate of the Month nodes aren't necessarily going to match what I want to display; I want to go by the nodeName. What's the best way to convert the 'MM' format text into a full month name?
Hi David,
I've always just used a lookup variable for this, e.g.:
With this in place, I can just use the apply-templates instruction to format any element containing a 01—12 value as a monthname, e.g.:
/Chriztian
Hi Chriztian,
Thanks for the reply. That looks like a good way to do it, I'll have to try it out. I discovered my own way to do it as well, and it's a lot simpler, but it seems like it might be bad practice:
<xsl:variable name="prMonthName">
2000-<xsl:value-of select="@nodeName"/>-01T01:00:00
xsl:variable>
(<xsl:value-of select="umbraco.library:FormatDateTime($prMonthName, 'MMMM')"/>)
Essentially, I am just adding in phony info to make the 'MM' string into a proper date string, and then using FormatDateTime to display only the month. It works, and it's very simple, but there might be a possibility of the phony info getting displayed somehow. Should I avoid doing this?
I could make it a little safer to use by using the document's creation date as a starting point, then overriding the month part, but that hurts its simplicity.
Hi David,
Your way is another good way of doing it - but you should be very careful with the prMonthName variable though (whitespace etc.) - best way to create it would be like this:
This way, you're not leaving anything up the processor, regarding which whitespace nodes are significant and should or should not be included. (Any extra whitespace would throw an exception when sent to the FormatDateTime() extension.)
The reason I use the other method is that more often than not, the design (or the client) needs some of the monthnames abbreviated - e.g.: "May", "June" and "July" are fine, but the others should be "Jan.", "Feb." etc.
One other benefit to yours, however, is that it will automatically output the monthnames in the chosen Culture for the node (e.g., if you're in a multilingual site)
/Chriztian
is working on a reply...