2

XPath 3.0 defines a new operator called the 'mapping operator'. It is denoted by the exclamation mark --!.

What does A!B mean? How do we use the ! operator? Could someone give me an example?

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
Chong Lip Phang
  • 8,755
  • 5
  • 65
  • 100

2 Answers2

1

Simple map operator (!) works rather like /, except there is no restriction that the left hand operand must be a node-set, and there is no sorting of results into document order.

For example, (1 to 7)!(.*.) returns the sequence (1, 4, 9, 16, 25, 36, 49).

Leo Chapiro
  • 13,678
  • 8
  • 61
  • 92
  • 1
    Am I right in thinking that `(1 to 7)!(.*., .+.)` returns `(1, 2, 4, 4, 9, 6, 16, 8, 25, 10, 36, 12, 49, 14)`? – Davio Sep 05 '14 at 08:26
  • Hi there. Thank you for your explanation. I wonder if there is any software that can evaluate XPath 3.0? I wish to test out its various new features. – Chong Lip Phang Sep 05 '14 at 08:31
  • 2
    @Davio Yes, Davio, exactly! Chong Lip Phang: You can test XPath 3.0 online e.g. http://videlibri.sourceforge.net/cgi-bin/xidelcgi – Leo Chapiro Sep 05 '14 at 08:40
  • 1
    Most of the products that support XPath 3.0 also support XQuery 3.0, which is a superset. Examples are Saxon and BaseX. – Michael Kay Sep 05 '14 at 11:00
1

Here's another example:

let $s := "The Taming of the Shrew"
return tokenize($s, ' ')!(string-length(.)||upper-case(.))

returns ("3THE", "6TAMING", "2OF", "3THE", "5SHREW")

This also uses the new string concatenation operator "||".

Michael Kay
  • 156,231
  • 11
  • 92
  • 164