I've been poking around an existing web part and have been having real troubles in pulling fields from a SharePoint List. I found this article extremely useful and basically found that this XSLT snippet saved me hours of debbugging:
<xsl:for-each select="@*">
P:<xsl:value-of select="name()" />
</xsl:for-each>
This basically outputs all the fields being parsed from the query in the XML which can be transformed by the XSLT. If there are fields missing from the list, as in my case, you actually need to customise the Content Query Web Part using CAML. This is also explained by exporting the webpart file and then editing the 'CommonViewFields' property element in the file. This took three hours of debugging to get to the bottom especially with the internal name madness! Heather Soloman has a great explanation of the best way to get to the Internal Names of the fields.
I also wrote some quick code to inspect the sites and then list out the fields with Title's and InternalName's for a specific one:
using (SPSite mySite = new SPSite("http://intranet/"))
{
SPWeb oWebsite = mySite.OpenWeb();
Console.WriteLine(oWebsite.Name);
foreach (SPList list in oWebsite.Lists)
{
Console.WriteLine(list.Title);
}
SPList oList = oWebsite.Lists["0"];
Console.WriteLine(oList.Lists.Count);
foreach (SPField oField in oList.Fields)
{
Console.WriteLine("'" + oField.Title + "' = '" + oField.InternalName + "'");
}
}