xsl-list
[Top] [All Lists]

Re: [xsl] XSLT 4 xsl:with

2020-05-20 02:32:45
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

On 5/20/20 6:06 AM, Mukul Gandhi gandhi(_dot_)mukul(_at_)gmail(_dot_)com wrote:
On Tue, May 19, 2020 at 2:23 PM Pieter Masereeuw pieter(_at_)masereeuw(_dot_)nl <mailto:pieter(_at_)masereeuw(_dot_)nl> <xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com <mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>> wrote:

    I would be very happy if I could make my intentions clearer by
    using a real XSLT construct in this situation, such as *<xsl:with
    select="...">.*

I think that, this would be a useful instruction for XSLT, for setting runtime context for other XSLT instructions. I also remember that, sometimes I used to use xsl:for-each to establish runtime context for other XSLT instructions, which is perhaps not good software engineering.


--
Regards,
Mukul Gandhi
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/3208261> (by email <>)
--~----------------------------------------------------------------
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>