Monday, February 25, 2008

Quick Reference for SharePoint Built in Fields

There are many instances where you need a quick, readable reference giving you the GUIDs for your FieldRef's in a content type definition file. Here's a handy xslt stylesheet that does the transform for you:

<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wss="http://schemas.microsoft.com/sharepoint/">

<xsl:output method="html" version="1.0" encoding="utf-8" indent="yes" />

<xsl:template match="wss:Elements">
<html>
<body>
<h2>SharePoint 2007 Built-In Fields</h2>
<table border="1" width="100%" style="font-size:10pt;">

<tr bgcolor="#9acd32">
<th align="left">Group</th>
<th align="left" width="100">Field</th>

<th align="left">Type</th>
<th align="left">Declaration</th>
</tr>
<xsl:apply-templates>

<xsl:sort select="@Group" />
<xsl:sort select="@Name" />
</xsl:apply-templates>
</table>

</body>
</html>
</xsl:template>
<xsl:template match="wss:Field">
<tr>
<td width="100"><xsl:value-of select="@Group"/></td>

<td width="100"><xsl:value-of select="@Name"/></td>
<td width="100"><xsl:value-of select="@Type"/></td>
<td>&lt;FieldRef ID=&quot;<xsl:value-of select="@ID"/>&quot; Name=&quot;<xsl:value-of select="@Name"/>&quot;/&gt;
</td>

</tr>
</xsl:template>
</xsl:stylesheet>



If you want everything done for you, save the above text into a file called "GenerateFieldDefs.xsl" and then save the below code into a document called "GenerateFieldDefs.html" and save both files into your SharePoint fields directory (..../12/TEMPLATE/FEATURES/fields). Then open the GenereateFieldDefs.html file with IE6 or Firefox 1.5 or higher.

Here's the html code:

<html>

<head>
<script>
function loadXMLDoc(fname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
xmlDoc.async=false;
xmlDoc.load(fname);
return(xmlDoc);
}

function displayResult()
{
xml=loadXMLDoc("fieldswss.xml");
xsl=loadXMLDoc("GenerateFieldDefs.xsl");
// code for IE
if (window.ActiveXObject)
{
ex=xml.transformNode(xsl);
document.getElementById("example").innerHTML=ex;
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation

&& document.implementation.createDocument)
{
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById("example").appendChild(resultDocument);
}
}
</script>
</head>
<body id="example" onLoad="displayResult()">
</body>
</html>


No comments: