xsl-list
[Top] [All Lists]

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

2022-06-02 07:09:54

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
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--


<Prev in Thread] Current Thread [Next in Thread>