Re: [xsl] Constructing complex xs:string in variable

Subject: Re: [xsl] Constructing complex xs:string in variable
From: "Liam R. E. Quin liam@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 10 Oct 2019 15:18:23 -0000
On Thu, 2019-10-10 at 12:45 +0000, Piez, Wendell A. (Fed)
wendell.piez@xxxxxxxx wrote:
> Also let's not forget
> <xsl:variable name="var" select="''prefix' || $somevar || 'part'"/>

Or one of the examples from my XSLT 3 course -

  ("boy", "with", "blue", "socks" ),
  function ($base, $new) {
    if (empty($base)) then $new else ($base || ' ' || $new)

which is starting to look like JavaScript.

You have to keep in mind the backgrounds of the people who will be
mantaining what you write, though. Using fold-left and a lambda
function is a little silly in an example of this size, and needlessly
complex, but in a larger example may make sense.

The string joining operator, expecially when combined with other new
operators such as -> and !, can also make XSLT veer away from being
document-oriented and crash head-long with the old vine-covered stone
wall of Perl or the modern concrete of Python.

So generally i prefer to use concat() and string-join if the people
reading the expressions will likely be document/text processing people.
But a bmodernb JavaScript programmer (say) would be entirely at home
with the example i just gave.

> I agree that the distinction between strings and text nodes is a fine
> one, but useful and important to understand. It represents one of the
> boundaries between the regimented world of the tree and the open
> world of XPath.

It also is a frequent problem for newcomers, who often expect text() to
be a function that returns the string value of a sub-tree. I wish it
had been called textnode() instead.


Liam Quin,
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations:

Current Thread