templates:copy-node is a real, public function in the html-templating package (confirmed in the installed 1.2.1 package's templates.xqm), but it's missing from the "Pre-defined Template Commands" section of the templating docs page, which otherwise documents templates:include, lib:include, templates:each, templates:if-parameter-set/if-parameter-unset, templates:surround, templates:form-control, templates:load-source (removed), and lib:parse-params.
Signature and current behavior, from templates.xqm:
declare function templates:copy-node($node as element(), $model as item()*) {
element { node-name($node) } {
$node/@*,
templates:process($node/*, $model)
}
};
A couple of behaviors worth documenting explicitly, since they're easy to get wrong without reading the source (I initially assumed both, incorrectly, before checking):
- It does not filter
@data-template/@data-template-* attributes from the copied node the way templates:process-children/wrapped functions do via templates:filter-attributes - they pass through into the output verbatim.
- It only recurses into element children (
$node/*), not all child nodes - text/comment children of the calling element are dropped, not just re-processed.
templates:copy-nodeis a real, public function in thehtml-templatingpackage (confirmed in the installed 1.2.1 package'stemplates.xqm), but it's missing from the "Pre-defined Template Commands" section of the templating docs page, which otherwise documentstemplates:include,lib:include,templates:each,templates:if-parameter-set/if-parameter-unset,templates:surround,templates:form-control,templates:load-source(removed), andlib:parse-params.Signature and current behavior, from
templates.xqm:A couple of behaviors worth documenting explicitly, since they're easy to get wrong without reading the source (I initially assumed both, incorrectly, before checking):
@data-template/@data-template-*attributes from the copied node the waytemplates:process-children/wrapped functions do viatemplates:filter-attributes- they pass through into the output verbatim.$node/*), not all child nodes - text/comment children of the calling element are dropped, not just re-processed.