functx:is-node-among-descendants
Whether an XML node is among the descendants of a sequence, based on node identity
Description
The functx:is-node-among-descendants function returns a boolean value indicating whether or not a node is in the specified sequence, or among the descendants of nodes in a sequence, based on node identity. If $node or $seq is the empty sequence, it returns false.
Nodes are identified based on node identity, not their contents. For a similar function based on the contents of a node, see functx:is-node-among-descendants-deep-equal.
Parameters |
Description |
|---|---|
node:node() |
the node to test |
seq:node() |
the sequence of nodes to search |
Examples
The examples below use this input document:
<xsl:variable name="in-xml" as="item()*">
<prices>
<price value="29.99" discount="10.00"/>
<price value="39.99" discount="6.00"/>
<price value="49.99" discount=""/>
</prices>
</xsl:variable>
<xsl:variable name="aPrice" as="item()*">
<price value="49.99" discount=""/>
</xsl:variable>
XPath |
Results |
|---|---|
functx:is-node-among-descendants($in-xml/price[1],$in-xml) |
true |
functx:is-node-among-descendants($in-xml,$in-xml/price[1]) |
false |
functx:is-node-among-descendants($in-xml,$in-xml) |
true |
functx:is-node-among-descendants($aPrice,$in-xml) |
false |
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-is-node-among-descendants.
[e] example-functx-is-node-among-descendants
[e] vars
[e] in-xml
[e] select
[v] copy-of(parse-xml('<prices><price value="29.99" discount="10.00"/><price value="39.99" discount="6.00"/><price value="49.99" discount=""/></prices>')/*)
[e] aPrice
[e] select
[v] copy-of(parse-xml('<price value="49.99" discount=""/>')/*)
[e] start
[e] match
[v] /
[e] body
[e] write-pattern
[v] examples
[e] patterns
[e] examples
[v] E01: {{ functx:is-node-among-descendants($in-xml/price[1],$in-xml) }}
[v] E02: {{ functx:is-node-among-descendants($in-xml,$in-xml/price[1]) }}
[v] E03: {{ functx:is-node-among-descendants($in-xml,$in-xml) }}
[v] E04: {{ functx:is-node-among-descendants($aPrice,$in-xml) }}