Re: [xsl] XPath equivalent to xsl:apply-templates?

Subject: Re: [xsl] XPath equivalent to xsl:apply-templates?
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 14 Jun 2022 04:03:13 -0000
> I am not sure the complexity is worth the convenience but it would
certainly be nice to have sometimes.

This certainly becomes inconvenient quickly, as a template may belong to a
set of modes, not just to one:  https://www.w3.org/TR/xslt-30/#using-modes

So, in the general case we will have not:

> local:doesThing#3@userDefined

but:

local:doesThing#3@userDefined1@userDefined2...@userDefinedN


we also will need a function:

      matches-pattern($item as item(), $match-pattern as xs:string())

The parameters to the function that emulates a  template need to be in two
groups: explicit and tunnel.

It seems that a description of this feature (emulating templates and
xsl:apply-templates) with XPath functions will require many pages, and this
number (I believe) is inversely proportional to the usability of the
feature.


Thanks,
Dimitre

On Mon, Jun 13, 2022 at 8:23 AM Graydon graydon@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> On Mon, Jun 13, 2022 at 01:55:39PM -0000, Michael Kay mike@xxxxxxxxxxxx
> scripsit:
> > I agree a functional equivalent to apply-templates would be useful.
> >
> > In trying to design it, the main stumbling block has been how to handle
> modes. We could make the mode-name a dynamically-defined QName argument,
> but that's then a new capability (dynamic modes) rather than a functional
> equivalent, and it raises questions in the context of 3.0 mode visibility
> and packages.
> >
> > An alternative design would be to use the mode name as the function
> name, or to find some other way of statically associating a function with a
> specific mode.
>
> This strikes me as adding an imaginary component to the function arity.
>
> So where now there's
>
> local:doesThing#2
> local:doesThing#4
>
> there'd be
>
> local:doesThing#2@current
> local:doesThing#4@current
> local:doesThing#3@userDefined
>
> (The choice of @ to indicate the mode is completely questionable, but
> there isn't a lot of punctuation just lying around unused.)
>
> By default, every function is in the special mode current; a user can
> specify they want a specific mode through some sort of semi-parameter
> mechanism so local:doesThing($a,$b) does what you'd expect but
> local:doesThing($a,$b,$c)@userDefined (or maybe
local:doesThing@userDefined($a,$b,$c)
> goes and finds the definition from
>
> <xsl:function name="local:doesThing" mode="userDefined as="returnType">
> ....
> </xsl:function>
>
> or
>
> declare function local:doesThing($a,$b,$c) as returnType mode userDefined {
> ....
> };
>
> In the specific case, it'd look like
>
> fn:apply-templates@modeName($someNodes)
>
> or (for #CURRENT or #DEFAULT and I'm not clear on which it should be)
>
> fn:apply-templates($someNodes)
>
>
> I am not sure the complexity is worth the convenience but it would
> certainly be nice to have sometimes.
>
>
> --
> Graydon Saunders  | graydonish@xxxxxxxxx
> CC&s oferC)ode, C0isses swC! mC&g.
> -- Deor  ("That passed, so may this.")
>
>
>

--
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.

Current Thread