Re: [xsl] How to cope with the complexity of an XSLT program with thousands of template rules?

Subject: Re: [xsl] How to cope with the complexity of an XSLT program with thousands of template rules?
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 2 Jun 2022 12:09:50 -0000
> Question: what techniques do you use to control the complexity of a large
XSLT program?
>

Modes, primarily. Aligned with modules, so one module holds all the rules for
one mode.

A technique I used in the Java-to-C# transpiler, which worked very nicely, was
to have two levels of despatch:

<xsl:template match="some-element" mode="mode-A">
  <xsl:apply-templates select="." mode="mode-B"/>
</xsl:template>


<xsl:template match="*[@class='one']" mode="mode-B">...</xsl:template>

<xsl:template match="*[@class='two']" mode="mode-B">...</xsl:template>


It makes it much easier for the human reader to work out which rules are going
to fire for which elements, and it makes it easier for the processor too.

In mode-A, if you know the element name, you know which rule will fire.

In mode-B, if you know the value of the @class attribute, you know which rule
will fire.

It's basically a two-level decision tree instead of a flat single-level
ruleset.

Michael Kay
Saxonica

Current Thread