<?xml version="1.0"?>
<!--
XSLT for identifying JIRA issues whose description or comment are greater than
4000 characters, the limit that JIRA sets on Oracle and Cloudscape field
lengths (see fieldtype-oracle.xml).  To be run against the XML backup generated
by JIRA.  Tested with JIRA 2.3 output.  Please send feedback to
http://support.atlassian.com or jeff@atlassian.com

Notes:

 - This is all obsolete now that Oracle 10g's JDBC driver works with
 CLOBS.  Please prefer that solution instead.  See:

   http://confluence.atlassian.com/display/JIRA/JIRA+3+workflows+in+Oracle

 - The Oracle limit is actually 4000 bytes, not 4000 characters, so if
 you use an 8-bit encoding like UTF-8, you will need to factor in 2-byte
 characters.

Usage:

Using JDK 1.4+:

  java org.apache.xalan.xslt.Process -IN jira_backup.xml -XSL jira_checklengths.xsl -PARAM url http://jira.atlassian.com

Using Saxon:

  java -jar $SAXON/saxon.jar jira_backup.xml jira_checklengths.xsl -url http://mycompany.com/jira

__ 
Copyright (c) 2003 Atlassian
$Revision: 1.4 $ 
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:output omit-xml-declaration="yes" method="text" indent="no"/>

  <xsl:param name="url" select="'http://localhost:8080'"/>
  <xsl:variable name="LINK" select="concat($url, '/secure/ViewIssue.jspa?key=')"/>

  <xsl:key name="issues" match="/entity-engine-xml/Issue" use="@id"/>

  <xsl:template match="/entity-engine-xml">
  	<xsl:text>Issues with descriptions over 4000 chars:
-------------------------------------
</xsl:text>
    <xsl:apply-templates select="Issue/description"/>
  	<xsl:text>
Issues with comments over 4000 chars:
-------------------------------------
</xsl:text>
    <xsl:apply-templates select="Action"/>
  </xsl:template>

  <xsl:template match="description">
    <xsl:if test="string-length(.) > 4000">
      <xsl:value-of select="concat($LINK, ../@key)"/><xsl:text>
</xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template match="Action/@body|body">
    <xsl:if test="string-length(.) > 4000">
      <xsl:variable name="id" select="../@id"/>
      <xsl:variable name="issue" select="../@issue"/>
      <xsl:variable name="author" select="../@author"/>
      <xsl:variable name="type" select="../@type"/>
      <xsl:for-each select="key('issues', ../@issue)">
        <xsl:value-of select="concat($LINK, @key, '#action_', $id)"/>	(<xsl:value-of select="$type"/> by <xsl:value-of
          select="$author"/>)<xsl:text>
</xsl:text>
      </xsl:for-each>
    </xsl:if>
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="@*|*|text()|processing-instruction()">
    <xsl:apply-templates select="@*|*|text()|processing-instruction()"/>
  </xsl:template>

</xsl:stylesheet>
