xsl-list
[Top] [All Lists]

Re: [xsl] XSLT 4 xsl:with

2020-05-20 22:13:47
Please also consider following.

Let there be following XSLT pseudocode, and explanation after that,

<xsl:template match="X">
    <xsl:for-each select="Y">
       <!-- something here -->
    </xsl:for-each>
</xsl:template>

The current node X, is the context of the current node in sequence Y.
Therefore, the concept of context is mostly (and correctly) already built
into the XSLT language.

On Wed, May 20, 2020 at 1:02 PM Pieter Masereeuw pieter(_at_)masereeuw(_dot_)nl 
<
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Thanks everyone for your comments. It is great to be part of a community
like this. You made me think better, and that's why I'd like share some
other thoughts on this subject.

It seems that XSLT has enough power to facilitate anything that you want
to do in processing XML (and other stuff). Also, as Gerrit pointed out, it
already has facilities like *@context-item* that you may want to extend
to other places as well, so no need for new words (Ockham's razor, more or
less).

My main point was that I wanted to express my intentions in a more natural
way. Therefore, I came up with <xsl:with> (I now like Graydon's
<xsl:with-context> better). The additional effect of a cardinality check
would also be very beneficial, because often, when I return to older code,
I wonder if my comment really/still applies and whether or not the
(implied) schema of the input may have changed in the meantime.

Now, of course, XSLT has an excellent facility for detecting such errors:
the @as attribute. So instead of *<xsl:with-context select="foo">* I
might write:

*<xsl:variable name="single-foo" as="element(foo)" select="foo"/>*
*<xsl:for-each select="$single-foo">*...
That would also have the benefit that it does not only specify the
expected cardinality, but also other type aspects.

Using a variable may be a bit verbose (but I do it quite often), so
instead of a new element like <xsl:with-context>, we might also extend the
idea behind type-checking. Adding an @as attribute to constructions like
xsl:for-each should be avoided (I think), because my intended semantics
would be different from its normal use. But maybe some new attribute with
the required checking effect, like for instance *@context-as*?

We then might have* <xsl:for-each select="foo" context-as="element(foo)">*
.

The @context-as attribute could then also be allowed on other constructs,
such as <xsl:apply-templates>, although I do see some difficulties in some
situations.

I must confess that, in the end, @context-as feels somewhat clumsy to me,
so I am still attracted to my initial idea of just writing
<xsl:with-context select="foo">. But then, maybe the type-checking idea
will trigger some new thoughts?

Pieter





-- 
Regards,
Mukul Gandhi
--~----------------------------------------------------------------
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>