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: "David Carlisle d.p.carlisle@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 2 Jun 2022 14:17:15 -0000
On Thu, 2 Jun 2022 at 12:45, Roger L Costello costello@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Hi Folks,
>
> I have an XSLT program with thousands of template rules.
>
> Ugh!
>
> It's too much complexity for my tiny brain.
>
> To help deal with the complexity I have implemented the following:
>
> 1. I split up the template rules across a number of files. Less template
> rules in a file seems to reduce the stress on my brain.
>

Yes, as Michael says, aligning this split with modes helps a lot.

>
> 2. I make extensive use of ENTITIES. I have come to love ENTITIES! They
> are super helpful -- way less errors -- to define a value in one place and
> then use the value (via an ENTITY reference) in many places.
>

I would avoid this. We did this  quite a bit for XSLT1 But, as your last
question showed, the entities are transparent to xpath and xslt processors.
It is generally better to share code via shared variables and functions so
the system (and human readers) can more easily see what is shared.


> 3. Hundreds of my template rules are empty, e.g.,
>
>     <xsl:template match="(sid|star)/supplementalData">
>         <xsl:param name="TRM_PAR_row" as="element(row)"/>
>     </xsl:template>
>
> er this seems wrong, especially the xsl:param on an empty template is
doing nothing.


> To shrink things, I changed those empty rules using the XML empty tag
> abbreviation, e.g.,
>
> <xsl:template match="(sid|star)/supplementalData"/>
>
> That helps make the files a bit shorter. Shorter is better for my brain.
>
> Question: what techniques do you use to control the complexity of a large
> XSLT program?
>
> /Roger

Current Thread