XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (386 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
11.61Mb size Format: txt, pdf, ePub
  • The expression is not associative if one of the steps creates new nodes. There is no expression in XPath itself that creates new nodes, but an XPath expression can contain a call to a function written in XSLT that creates such nodes. In XQuery, steps in a path expression can even construct nodes directly, for example, you can write

    /@q
    . If we use the XQuery syntax for illustration, we can see that
    $A/../
    eliminates duplicate nodes in the result of
    $A/..
    , and therefore the number of

    elements in the result is equal to the number of distinct nodes that are parents of nodes in
    $A
    . But the expression
    $A/(../)
    creates one

    element for every node in
    $A
    that has a parent. So the number of

    elements returned in the two cases is different.

  • The expression is not associative if one of the steps uses the
    position()
    or
    last()
    functions. For example, consider the expression
    A/remove($S, position())
    . The
    remove()
    function, described in Chapter 13, returns the sequence of items supplied in its first argument, except for the item whose position is given in the second argument. This means that if A contains exactly one node, then the result is all the nodes in
    $S
    except the first. But if A contains two nodes, then the result is the union of
    remove($S, 1)
    and
    remove($S, 2)
    , which (think about it carefully) contains all the nodes in
    $S
    . Now if we extend this to the expression
    A/B/remove($S, position())
    we can see that the result should contain all the nodes in
    $S
    except when
    A/B
    contains exactly one node, because the expression should be evaluated as
    (A/B)/remove($S, position())
    . But if it were written the other way, as
    A/(B/remove($S, position))

Other books

The City and the Stars by Arthur C. Clarke
The Amish Clockmaker by Mindy Starns Clark
Killer Kisses by Sharon Buchbinder
Celia Kyle by He Ain't Lion
Only Skin Deep by Levey, Mahalia
The Winter Witch by Paula Brackston

© 100 Vampire Novels China Edition 2015 - 2024    Contact for me [email protected]