Microsoft Dynamics CRM – Plugin Tool Export XSLT

I have been tasked with documenting our Microsoft Dynamics CRM 4.0 plug-ins and workflows, and have created a simple way to visualize the contents exported by the CRM Plugin Registration Tool.

The tool exports details about selected assemblies into XML format. An easy way to create visualizations for XML is to utilize XSLT (XML stylesheets).  I have created a simple XSLT, which results in the exported file looking like the image below:

The result of applying the XSLT

The result of applying the XSLT

The nice thing about this is that using basic XSL the contents of the export can be manipulated into a variety of different visual representations. I have chosen a very simple, tabular layout with the items grouped by entity, then sorted by message, order of execution, and finally by the name of the plug-in. The XSL is posted after the break.

In order to get this to work two lines must be added to the beginning of the plugin export XML:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="workflows.xsl" ?>

Once that is added, it is then simply a matter of creating the “plugins.xsl” file and viewing the XML in a compatible browser. The XSL file contents can be adjusted for coloring, or to even add images and behavior if so desired. It is a little longer than it needs to be because I have included the style information in the file itself.

XSL Code:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- 
ADD THIS TO THE BEGINNING OF THE ExportSolution.xml 
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="plugins.xsl" ?>
 -->
<xsl:key name="primaryentities" match="Step" use="@PrimaryEntityName" />			
<xsl:template match="Register">
<html>
<head><title>Plugin Diagram</title>
	<style type="text/css">
	body { font-family: Arial; font-size: 62.5%;background: #369; }
	h3 { color: #fff; }
	h4 { padding:2px 5px; margin:25px 0 0 0; background: #333; 
		color: #fff;font-weight:bold; text-transform:uppercase; display:none;}
	hr { margin: 20px 0; }
	table { border: 2px solid #333; margin:0; padding:0; 
		border-collapse: collapse; width: 100%; font-size: 1.2em;}
	tr, td { margin:0; padding: 2px; }	
	th { background: #fff; }
	td { border: 1px solid #333; }
	tr.Create { background: #dfd; }
	tr.Delete { background: #fdd; }
	tr.Update { background: #dff; }
	tr.SetState { background: #eee; }
	tr.SetStateDynamicEntity { background: #ddd; }
 
	.entitycol { }
	.rank, .mode, .stage { text-align: center; width: 35px; }
	.message { width: 140px; }
	.plugin { width: 310px; }
	.mode0, .stage10 { background: #6C6; color:white; }
	.mode1, .stage50 { background: #C66; color:white;}
	.light { background: #EEE; }
	.dark { background: #CCC; }
	</style>
</head>
<body>
<h3>
	<xsl:value-of select="@Server" />.
	<xsl:value-of select="@Domain" />/
	<xsl:value-of select="@Org" />
</h3>
	<table>		
	<tr>
		<th class="entitycol">Entity</th>
		<th>Order</th>
		<th>Message</th>
		<th>Plugin</th>
		<th>Description</th>
		<th>Mode</th>
		<th>Stage</th>
	</tr>
<xsl:for-each select="//Step[generate-id() = 
	generate-id(key('primaryentities',@PrimaryEntityName)[1])]">
<xsl:sort select="@PrimaryEntityName" />
	<xsl:variable name="entity" select="@PrimaryEntityName" />
	<xsl:for-each select="//Step[@PrimaryEntityName=$entity]">
		<xsl:sort select="@MessageName" />
		<xsl:sort select="@Rank" />
		<xsl:sort select="@PluginTypeName" />
	<tr><xsl:attribute name="class">
			<xsl:value-of select="@MessageName" />
		</xsl:attribute>
		<td class="entitycol">
			<xsl:value-of select="@PrimaryEntityName" />
			<xsl:choose>
				<xsl:when test="@SecondaryEntityName='none'"></xsl:when>
				<xsl:otherwise>
					<br />
					<xsl:value-of select="@SecondaryEntityName" />
				</xsl:otherwise>
			</xsl:choose>
		</td>
		<td class="rank"><xsl:value-of select="@Rank" /></td>
		<td class="message"><xsl:value-of select="@MessageName" /></td>
		<td class="plugin"><xsl:value-of select="@PluginTypeName" /></td>
		<td class="desc"><xsl:value-of select="@Description" /></td>
		<td><xsl:attribute name="class">
			stage stage<xsl:value-of select="@Stage" /></xsl:attribute>
			<xsl:choose>
				<xsl:when test="@Mode=0">Sync</xsl:when>
				<xsl:otherwise>Async</xsl:otherwise>
			</xsl:choose>
		</td>
		<td>
		<xsl:attribute name="class">
			mode mode<xsl:value-of select="@Mode" />
		</xsl:attribute>
			<xsl:choose>
				<xsl:when test="@Stage=10">Pre</xsl:when>
				<xsl:otherwise>Post</xsl:otherwise>
			</xsl:choose>
		</td>
	</tr>						
	</xsl:for-each>
</xsl:for-each>
	</table>
 
<hr />
<table>		
	<tr>
		<th class="assembly">Assembly</th><th>Workflow</th>
	</tr>
	<xsl:for-each select="//WorkflowType">
	<xsl:sort select="@TypeName" />
	<xsl:variable name="rowclass">
		<xsl:choose>
			<xsl:when test="position() mod 2 = 0">light</xsl:when>
			<xsl:otherwise>dark</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
		<tr>
		<xsl:attribute name="class">
			<xsl:value-of select="$rowclass" />
		</xsl:attribute>
			<td class="assemblycol"><xsl:value-of select="../../@Assembly" /></td>
			<td class="workflow"><xsl:value-of select="@TypeName" /></td>
		</tr>						
	</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
This entry was posted in Development. Bookmark the permalink.

One Response to Microsoft Dynamics CRM – Plugin Tool Export XSLT

  1. sgp says:

    Very cool!

    I think it’d be great to transform the Plugin Registration Tool xml into the Plugin Development xml too.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">