Re: [xsl] Measuring the complexity of XSLT stylesheets

Subject: Re: [xsl] Measuring the complexity of XSLT stylesheets
From: "M. David Peterson" <m.david.x2x2x@xxxxxxxxx>
Date: Sun, 17 Apr 2005 13:23:43 -0600
To be honest I have to disagree with any theory that blames the size
of something as the problem...  if its a fairly deep XML infoset with
disparate data types and values galore your XSLT file will, more than
likely, require a lot of templates to properly to process the data.

Again, I think Colin nailed it with the XPath sentence (nice touch
Colin ;)...  take the following for example:

<xsl:for-each select="/foo/bar[@son_of_bar =
'baby_bar']/preceding:sibling::*[local-name() !=
'little_itty_bitty_foo' and $time_of_day != 'noon' and $phase_of_moon
!= 'full']/@whodafoo =
'great_grand_foo']/following-sibling::barnone/ancestor::*[@statement =
'whodafooismydaddy?']/descendant-or-self::waitwhat =
'arentwebackwherewestarted?'">
<xsl:for-each select="ah-hell-herewegoagain">
STOP THE MADNESS!!!
</xsl:for-each>
</xsl:for-each>

While I cant speak for anybody else I know I can say with clear
conscience that the above XPath statement and nested xsl:for-each
instructions are an ALL to common occurence when you first start
programming in XML/XSLT and NOTHING compared to just how bad an
attempt to "logically" process XML like this can get.  The secret?

<snip/>

<xsl:apply-templates select="child_element"/>

<xsl:template match="child_element">
... output a value
<xsl:apply-templates/>
</xsl:template>

... more templates to match each element against to determine if it
should be processed further or left alone to be handled by another
template.



On 4/17/05, Lars Marius Garshol <larsga@xxxxxxxxxxxxxxx> wrote:
>
> * Ben Pickering
> |
> | Something maybe related to the size of the tree resulting from
> | parsing the XPath expression?  The two examples given would be
> | closer under this metric than the length of their string
> | representations...
>
> True. This metric is clearly better than the character count (which I
> had in my original posting, anyway), since it is at least independent
> of the length of the element type names and the use of whitespace. It
> might not be too hard to write Python script that uses some Python or
> Java XPath parser to compute this metric.
>
> --
> Lars Marius Garshol, Ontopian         <URL: http://www.ontopia.net >
> GSM: +47 98 21 55 50                  <URL: http://www.garshol.priv.no >
>
>


--
<M:D/>

:: M. David Peterson ::
XML & XML Transformations, C#, .NET, and Functional Languages Specialist

Current Thread