January 2011 Archives

My favorite HTTP trace tool is Charles. I use it a lot to capture the underlying messages that fly between federation partners. Often, I'll save these traces and send them to colleagues for review. Rather than just sending the trace though, I sometimes include an ordered list of the transactions in the body of my emails. To create this list quickly, I export the trace from Charles in XML format, and I run the following XSLT stylesheet over it:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>

<xsl:template match="charles-session">
<ol>
<xsl:apply-templates select="transaction"/>
</ol>
</xsl:template>

<xsl:template match="transaction">
<li>
<xsl:value-of select="@protocol"/>
<xsl:text>://</xsl:text>
<xsl:value-of select="@host"/>
<xsl:if test="@port">
<xsl:text>:</xsl:text>
<xsl:value-of select="@port"/>
</xsl:if>
<xsl:value-of select="@path"/>
<xsl:if test="@query">
<xsl:text>?</xsl:text>
<xsl:choose>
<xsl:when test="string-length(@query) > 80">
<xsl:value-of select="substring(@query, 0, 80)"/>
<xsl:text>...</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@query"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</li>
</xsl:template>
</xsl:stylesheet>
The result is some HTML that I can copy/paste into my email client w/ the hope that my colleagues will not even need to open the complete trace.

HTH!