functx:dynamic-path
Dynamically evaluates a simple XPath path
Description
The functx:dynamic-path function dynamically evaluates a simple path expression. The function only supports element names and attribute names preceded by @, separated by single slashes. The names can optionally be prefixed, but they must use the same prefix that is used in the input document. It does not support predicates, other axes or other node kinds. Note that most processors have an extension function that evaluates path expressions dynamically in a much more complete way.
Parameters |
Description |
|---|---|
parent:node() |
the root to start from |
path:string() |
the path expression |
Examples
The examples below use this input document:
<xsl:variable name="in-xml" as="item()*">
<authors>
<author test="abc">
<first>Kate</first>
<last>Jones</last>
</author>
<author>
<first>John</first>
<a:last xmlns:a="http://a">Doe</a:last>
</author>
</authors>
</xsl:variable>
XPath |
Results |
|---|---|
functx:dynamic-path($in-xml,'author/first') |
<first>Kate</first> <first>John</first> |
name(functx:dynamic-path($in-xml,'author/@test')) |
test |
functx:dynamic-path($in-xml,'author') |
<author test="abc"> <first>Kate</first> <last>Jones</last> </author> <author> <first>John</first> <a:last xmlns:a="http://a">Doe</a:last> </author> |
functx:dynamic-path($in-xml,'author/a:last') |
<a:last xmlns:a="http://a">Doe</a:last> |
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-dynamic-path.
[e] example-functx-dynamic-path
[e] vars
[e] in-xml
[e] select
[v] copy-of(parse-xml('<authors><author test="abc"><first>Kate</first><last>Jones</last></author><author><first>John</first><a:last xmlns:a="http://a">Doe</a:last></author></authors>')/*)
[e] start
[e] match
[v] /
[e] body
[e] write-pattern
[v] examples
[e] patterns
[e] examples
[v] E01: {{ functx:dynamic-path($in-xml,'author/first') }}
[v] E02: {{ name(functx:dynamic-path($in-xml,'author/@test')) }}
[v] E03: {{ functx:dynamic-path($in-xml,'author') }}
[v] E04: {{ functx:dynamic-path($in-xml,'author/a:last') }}