XSLT lingual extensions?

Thinking of macro in XSLT...

In many programming languages the capability of extending lingual
constructs been found not just a useful but even not-separable part of the
language itself.  For example, the macros in C are an essential part of the
standard and almost any shared code.

XSLT itself has some capability to extend its own functionality inside of
XPath. Which is powerful for data and string utilities but does not give
much on the integration of markup itself.

During  Declarative Custom Element proposal preparation I faced the
challenge of TEMPLATE tag syntax into XSLT translation. The SLOT tag can be
easily expressed via <value-of  select=...

function slot2xsl( s )
{
    const v = document.createElementNS( XSL_NS_URL, 'value-of' );
    v.setAttribute( 'select', `//*[@slot="${ s.name }"]` );
    s.parentNode.replaceChild( v, s );
}

While for POC(link <https://unpkg.com/@epa-wg/custom-element@0.0/index.html>)
it is OK kind of XSLT pre-processing on JS level, the XSLT by itself is the
best for such kind of XSLT-to-XSLT transformation. As optimization, the
XSLT pipeline could be set but it means extra step and disconnection
between the HTML template source and final transformation. The less steps
in the pipeline, the better DX/DE( Developer Experience/Developer
Efficiency).

Hence proposing the macro definition for XSLT:
defined construct would be transformed into XSLT one and treated as inline
XSLT.

<slot name="slot1"> 😃</slot>

translated into

<xsl:value-of select='//*[@slot="slot1"]'/>

I guess there is no need for new XSLT syntax to support macro definition,
the usual

<xsl:template match="slot">
   <template:value-of><xsl:attribute name="select"
>//*[@slot="<xsl:value-of
select="@name">"]</xsl:attribute></template:value-of>

would be sufficient with one extra exception on the pipe priority so it
would run during the XSLT load ( and take XSLT itself as data) instead of
the transformation phase.

🤔 How to
* present the XSLT load vs transformation phase
* present the output XSLT ( via template: namespace?)

-s

Received on Monday, 2 January 2023 20:23:48 UTC