Re: Must variables that contain maps be typed?
"Imsieke, Gerrit, le-tex" <[email protected]>
| Newsgroups | gmane.text.xml.saxon.help |
|---|---|
| Organization | le-tex publishing services GmbH |
| Message-ID | <[email protected]> |
I think this "wrapping in a document node in the absence of an as attribute" is explained in the note after https://www.w3.org/TR/xslt-30/#dt-immediate-result Regardless of the current example of a map, where wrapping in a document node is almost never wanted, it is important to explain the difference between sequence constructors with or without as attribute to novices and sometimes also to more experienced users: <xsl:variable name="foo"> <bar/> </xsl:variable> $foo/bar -> <bar/> <xsl:variable name="foo" as="element(bar)> <bar/> </xsl:variable> $foo/bar -> () $foo/self::bar -> <bar/> The failure to understand this difference leads many desperate XSLT developers to use $foo//bar without ever knowing whether (which) one of the single-slash variants would have worked, too. And then try to explain to them that // is actually a shorthand for /descendant-or-self::node()/ ... (https://www.w3.org/TR/xpath-31/#abbrev) At least I find it comforting to know that XPath/XQuery/XSLT processors don't process input or stylesheets nilly-willy, and that it usually pays to know the exact rules, even though trying to look them up in a plethora of specifcations can be daunting. Gerrit On 17.08.2020 17:57, Michael Kay wrote: >> >> i thought the general rule was that it was never mandatory to specify >> a type. >> > > Specifying a type on a variable that contains a sequence constructor > suppresses the default action of constructing a document node. > > If the xsl:variable contains a sequence constructor that delivers a map, > it is never appropriate to wrap this in a document node, so the "as" > attribute is effectively mandatory. > > Michael Kay > Saxonica > > _______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ [email protected] https://lists.sourceforge.net/lists/listinfo/saxon-help