xsl-list
[Top] [All Lists]

Re: [xsl] Things that make you go Hmmmm!

2014-03-29 10:40:27

On 29-3-2014 16:11, Michael Sokolov wrote:
On 3/29/2014 10:43 AM, Abel Braaksma (Exselt) wrote:

While a tempting idea, it wouldn't work in practice I think, even if,
for a moment, we ignore backward compatibility issues. Consider the
identity template, the deepest copy always ends up with an empty
selection in the xsl:apply-templates. This is effectively the same as an
empty sequence constructor. Your proposal would mean that:

<xsl:copy />

and

<xsl:copy>
    <xsl:apply-templates select="()" />
</xsl:copy>

would both behave differently, depending on the context node. The first
would copy the whole subtree without further processing, the second,
which also has an effectively empty sequence constructor, would only
copy the current node without its children.
I don't think I understand this.  Are you saying that <xsl:template
match="@*|node()"> matches the empty sequence? That would be quite
surprising to me.  I can see that <xsl:apply-templates /> on an empty
node could cause an attempt to match an empty sequence, but does that
actually fire rules?

No, not directly. I meant to say that in the modified identity template
example that I gave, the processor will recursively go through all
nodes, and eventually will reach an attribute (in which case "@*|node()"
will select nothing) or a leaf node like text() or
processing-instruction() (in which case it will also select nothing).
The result of those deepest iterations is that there is nothing to copy
anymore and xsl:copy will do nothing.

My point was that it might lead to surprises if such a statement that
does not select anything, is used directly. Hence my select="()". In the
event where we were to allow your proposal of having xsl:copy also
behave as xsl:coy-of, I think this case will lead to problems in
practice, because you effectively say "when xsl:copy has no sequence
constructor, copy everything, when it has an empty sequence constructor
or one that selects an empty node set, copy nothing".

Yeah, I think that priniciple is over-stressed - as I said in an
earlier post, I think judicious suprises can be an essential spur to
learning, but I recognize this is a matter of taste.

True, and no language in existence will ever give the same surprises
everywhere and to everyone. People come to a language with different
backgrounds and different use-cases, leading to different learning
curves. and hence different surprises. It is up to the language
designers to try to make them as few as possible, but there always comes
a time when someone thinks there are too many of those surprises, or in
the wrong spots of the language. Which in turn, keeps us sharp ;).

Cheers,

Abel Braaksma
Exselt XSLT 3.0 processor
http://exselt.net

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--