functx:last-node

The XML node in a sequence that is last in document order

Description

The functx:last-node function returns the node in the sequence that appears last in document order (regardless of their order in the sequence). If nodes in the sequence are from multiple documents, the choice of which document is last is implementation-dependent.

Parameters

Description

nodes:node()

the sequence of nodes

Examples

The examples below use this input document:

<xsl:variable name="in-xml" as="item()*">
  <authors>
     <author>
        <fName>Kate</fName>
        <lName>Jones</lName>
     </author>
     <author>
        <fName>John</fName>
        <lName>Doe</lName>
     </author>
  </authors>
</xsl:variable>

XPath

Results

functx:last-node($in-xml//fName)

<fName>John</fName>

functx:last-node(($in-xml//lName, $in-xml//fName))

<lName>Doe</lName>

In a generator

Copy the snippet below and paste it in Freemapper, under a language node inside the generators element. Each line of the pattern prints the result of one example; to see them, run mi generate <project> <language> example-functx-last-node.

[e] example-functx-last-node
    [e] vars
        [e] in-xml
            [e] select
                [v] copy-of(parse-xml('<authors><author><fName>Kate</fName><lName>Jones</lName></author><author><fName>John</fName><lName>Doe</lName></author></authors>')/*)
    [e] start
        [e] match
            [v] /
        [e] body
            [e] write-pattern
                [v] examples
    [e] patterns
        [e] examples
            [v] E01: {{ functx:last-node($in-xml//fName) }}
            [v] E02: {{ functx:last-node(($in-xml//lName, $in-xml//fName)) }}

See Also