I was adding various lists on pages using XsltListViewWebPart as shown in the code below:
However, the Calendar view of a Calendar list was not getting applied using this code. I found that if XsltListViewWebPart is modified through UI and calendar view is applied; the Calendar view gets applied properly. When I opened the page using SharePoint Designer I found that the webpart had changed to ListViewWebPart.
So, the code had to be modified to use ListViewWebPart as shown: