functx:remove-elements-not-contents
Removes descendant XML elements but keeps their content
Description
The functx:remove-elements-not-contents function removes descendant elements from all of the nodes in $nodes based on name, but keeps the contents of the removed elements. This is useful, for example, for removing in-line formatting. The $names argument is a sequence of strings that represent element names to remove. Prefixes can (and must) be used in the $names values for elements that are prefixed in the input documents. You can also specify wildcard values “*”, “:” and “:” in the second argument. See the description for functx:name-test for details.
Parameters |
Description |
---|---|
nodes:node() |
the root(s) to start from |
names:string() |
the names of the elements to remove |
Examples
XPath |
Results |
---|---|
functx:remove-elements-not-contents($in-xml-1, ‘b’) |
<in-xml> <a>b1<c>c1</c> </a> <c>Mixed content</c> </in-xml> |
functx:remove-elements-not-contents($in-xml-1, (‘b’,’c’)) |
<in-xml> <a>b1c1</a>Mixed content </in-xml> |
functx:remove-elements-not-contents($in-xml-1, ‘a’) |
<in-xml> <b>b1</b> <c>c1</c> <c>Mixed <b>content</b> </c> </in-xml> |
functx:remove-elements-not-contents($in-xml-2, ‘x:b’) |
<in-xml> <a> <b>b1</b> <c>c1</c> </a> <c>Mixed content</c> </in-xml> |