Monday, January 18, 2010

Updated XSLT for CC.NET in SharePoint

Just modded my XSLT for viewing the CC.NET status of the buildserver in the XML Webpart of Sharepoint 2007:


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="yes" />
  <xsl:template match="/">
    <table border="0" cellpadding="0" cellspacing="0">
      <thead class="ms-viewheadertr">
        <th style="text-align:left;" scope="col" class="ms-vh2-nograd" nowrap="nowrap">Project</th>
        <th class="ms-vh2-nograd" >&#160;</th>
        <th style="text-align:left;" scope="col" class="ms-vh2-nograd" nowrap="nowrap">Status</th>
        <th class="ms-vh2-nograd" >&#160;</th>
        <th style="text-align:left;" scope="col" class="ms-vh2-nograd" nowrap="nowrap">Last buildtime</th>
        <th class="ms-vh2-nograd" >&#160;</th>
        <th style="text-align:left;" scope="col" class="ms-vh2-nograd" nowrap="nowrap">Buildlabel</th>
        <th class="ms-vh2-nograd" >&#160;</th>
        <th style="text-align:left;" scope="col" class="ms-vh2-nograd" nowrap="nowrap">Activity</th>
      </thead>
      <tbody>
        <xsl:apply-templates select="/CruiseControl/Projects/Project">
          <xsl:sort select="@name"/>
        </xsl:apply-templates>
      </tbody>
    </table>
  </xsl:template>
 
  <xsl:template match="Project">
    <tr>
  <xsl:if test="position() mod 2 != 1">
    <xsl:attribute  name="class">ms-alternating</xsl:attribute>
  </xsl:if>
      <td class="ms-vb2" align="top" nowrap="nowrap">
        <xsl:element name="a">
          <xsl:attribute name="onfocus">OnLink(this)</xsl:attribute>
          <xsl:attribute name="href">
            <xsl:value-of select="@webUrl"/>
          </xsl:attribute>
          <xsl:attribute name="onclick">GoToLink(this);return false;</xsl:attribute>
          <xsl:attribute name="target">_self</xsl:attribute>
          <xsl:value-of select="@name"/>
        </xsl:element>
      </td>
      <td>&#160;</td>
      <xsl:element name="td">
        <xsl:attribute name="class">ms-vb2</xsl:attribute>
        <xsl:attribute name="align">top</xsl:attribute>
        <xsl:attribute name="style">padding-bottom: 3px;
        <xsl:choose>
          <xsl:when test="@lastBuildStatus='Failed'">
            color:red;
          </xsl:when>
          <xsl:when test="@lastBuildStatus='Exception'">
            color:red;
          </xsl:when>
          <xsl:when test="@lastBuildStatus='Unknown'">
            color:yellow;
          </xsl:when>
          <xsl:when test="@lastBuildStatus='Failure'">
            color:red;
          </xsl:when>
          <xsl:otherwise>
            color:green;
          </xsl:otherwise>
        </xsl:choose>
        </xsl:attribute>
        <xsl:value-of select="@lastBuildStatus"/>
      </xsl:element>
      <td>&#160;</td>
      <td class="ms-vb2" style="padding-bottom: 3px;" align="top">
        <xsl:value-of select="substring-before(@lastBuildTime,'T')"/>&#160;
        <xsl:value-of select="substring-before(substring-after(@lastBuildTime,'T'),'.')"/>
      </td>
      <td>&#160;</td>
      <td class="ms-vb2" style="padding-bottom: 3px;text-align:right;" align="top">
        <xsl:value-of select="@lastBuildLabel"/>
      </td>
      <td>&#160;</td>
      <xsl:element name="td">
        <xsl:attribute name="class">ms-vb2</xsl:attribute>
        <xsl:attribute name="align">top</xsl:attribute>
        <xsl:attribute name="style">
          padding-bottom: 3px;
          <xsl:choose>
            <xsl:when test="@activity='Building'">
              color:red;
            </xsl:when>
           <xsl:when test="@activity='CheckingModifications'">
            color:yellow;
          </xsl:when>
            <xsl:otherwise></xsl:otherwise>
          </xsl:choose>
        </xsl:attribute>
        <xsl:value-of select="@activity"/>
      </xsl:element>
    </tr>
  </xsl:template>
</xsl:stylesheet>

No comments: