Re: [xsl] Measuring the complexity of XSLT stylesheets

Subject: Re: [xsl] Measuring the complexity of XSLT stylesheets
From: Adam Turoff <adam.turoff@xxxxxxxxx>
Date: Tue, 19 Apr 2005 16:31:34 -0400
On 4/17/05, Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote:
> On 4/18/05, Lars Marius Garshol <larsga@xxxxxxxxxxxxxxx> wrote:
> > * Dimitre Novatchev
> > | Cyclomatic Complexity (McCabe) [...]
> > | Halstead Complexity Measures [...]
> > | Henry and Kafura metrics [...]
> > | Bowles metrics [...]
> > | Troy and Zweben metrics [...]
> > | Ligier metrics [...]

Those traditional metrics feel unsatisfying for XSLT.  They all presume
to be analyzing static program text to produce a single scalar value
called "complexity".

With XSLT, the codepaths are determined by the input, so traditional
complexity analysis doesn't really address the problem.  For example,
it's impossible to know if:

    <xsl:apply-templates/>

can trigger zero, one or many templates in a stylesheet.

> > These might all be applicable, but does anyone know of any
> > implementations of these for XSLT?
>
> I don't know of any implementations for XSLT -- these would be best
> implemented as part of an XSLT processor.

This, however, is quite an intriguing idea -- calculate complexity
by tracing stylesheet execution while processing an input document.
Or a series of input documents, varying in complexity.  (Of course,
what constitutes "complexity of an XML document" is a separate
discussion.  ;-) )

Off the top of my head, here are some things that might contribute to
overall stylesheet complexity:

* number of XSLT modules loaded
* overall size of the XSLT stylesheet loaded
  (bytes / nodes post-include, post-import)
* percentage of templates used
* average template size (bytes, nodes, operators, XPath evaluations)
* ratio of input to output size (nodes, bytes)
* percentage of calculated vs. copied output

For example, if I'm processing this DocBook document:

    <book/>

I think we can all agree that there are 57 ways to call the DocBook XSL
stylesheets "complex", at least compared to this stylesheet, which
produces the same output:

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

:-)

-- Adam

Current Thread