[Top] [All Lists]

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

2019-10-10 10:18:28
On Thu, 2019-10-10 at 12:45 +0000, Piez, Wendell A. (Fed)
wendell(_dot_)piez(_at_)nist(_dot_)gov 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 “modern” 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, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations:  http://www.fromoldbooks.org
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>