xsl-list
[Top] [All Lists]

Re: [xsl] Best practice for typing?

2019-11-23 02:11:23
Hi David,

To me it seems best to specify the type as often as possible, but I must
confess that I do not always live by my rule - I just forget, or I am lazy.

Anyway, I always supply the type for the formal parameters inside a
function or named-template definition. When calling such templates, I
often forget (because Saxon will warn me anyway). When calling a
function, I don't think it is possible to specify the type, so if a
processor is capable of checking parameter types there, it is probably
also capable of doing the same check when calling a named template.

Parameters of pattern templates ("match=") may be more difficult to
check at compile time - maybe even impossible. In such cases, including
tunnel parameters, I specify the type, or at least, I hope that I do so.

I also have the habit of avoiding complex XPath-expressions - I
calculate such expressions in a number of steps, using typed variables.
Giving the subexpression a name helps to make my code clearer and it
also documents my thinking. As an extra benefit, adding the type will
help to flag errors at the most appropriate place.

Pieter

On 11/23/19 2:44 AM, David Birnbaum djbpitt(_at_)gmail(_dot_)com wrote:
Dear xsl-list,

Is there a consensus about best practice with respect to possibly
redundant typing? For example, we can specify a type using @as on
corresponding <xsl:param> and <xsl:with-param> elements, but if the
type is specified on <xsl:param>, it seems as if that might make it
redundant also to specify it on <xsl:with-param>, since using the
wrong type at the level of <xsl:with-param> will be caught by the type
specification on <xsl:param> anyway. Similarly, if I construct the
return value of a function by using <xsl:sequence> inside the body of
the function, I can specify the typing on <xsl:sequence>, but also on
<xsl:function>, and it seems as if specifying it in either of those
places will catch the same errors as specifying in both. (I am only
beginning to learn to use schema-aware processing, and therefore less
certain about how specifying @type when constructing an interim
element or attribute interacts with specifying @as when using it.)

Is there consensus among XSLT developers about whether it might be
better to use @as everywhere it is allowed, or, alternatively, better
to avoid using it redundantly? What is the practice of other readers
of this list?

Thanks,

David
djbpitt(_at_)gmail(_dot_)com <mailto:djbpitt(_at_)gmail(_dot_)com>
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
--~--

Attachment: signature.asc
Description: OpenPGP digital signature

<Prev in Thread] Current Thread [Next in Thread>