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 10:25:41
Hi Roger,

Question: what techniques do you use to control the complexity of a large
XSLT program?

Answer: Use function libraries and Functional Programming.

Through the years (since 2002) I have consistently used FXSL to solve many
problems considered "not for XSLT" or "almost unsolvable with XSLT".

It deserves to have a look back in time. See for example, how the templates
of the random.xsl module of FXSL are organized:
http://fxsl.sourceforge.net/articles/Random/Casting%20the%20Dice%20with%20FXSL-htm.htm

For some time I have been developing what could be considered the XPath
equivalent of FXSL. Using XPath function libraries can be the ultimate
approach at systematically using the FP style and techniques. One can
implement and reuse complete,  new and reusable data-types (data
structures) that significantly facilitate problem solving via abstraction
and application of well-known algorithms using these data types.

See for example this: "The Binary Search Tree Data Structure–having fun
with XPath 3.0" at
https://dnovatchev.wordpress.com/2012/01/09/the-binary-search-tree-data-structurehaving-fun-with-xpath-3-0/,
which was implemented 10 years ago.

Around the same time I described how to implement recursion within
anonymous functions, and thus fully use the FP style in XPath.

One can also build "objects" and "interfaces" with maps, whose "leaf-nodes"
values are functions.Passing these as parameters, one can implement
dependency injection and testability.

And we can go on and on...

Thanks,
Dimitre

On Thu, Jun 2, 2022 at 4:45 AM Roger L Costello costello(_at_)mitre(_dot_)org <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> 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.

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.

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>

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




-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.
--~----------------------------------------------------------------
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>