blob: 4b6bf462bc8fb9092705a23860c249e029fa42c5 [file] [log] [blame]
<!doctype html>
<!-- Generated by FreeMarker/Docgen from DocBook -->
<html lang="en" class="page-type-section">
<head prefix="og: http://ogp.me/ns#">
<meta charset="utf-8">
<title>Built-ins for nodes (for XML) - Apache FreeMarker Manual</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="format-detection" content="telephone=no">
<meta property="og:site_name" content="Apache FreeMarker Manual">
<meta property="og:title" content="Built-ins for nodes (for XML)">
<meta property="og:locale" content="en_US">
<meta property="og:url" content="https://freemarker.apache.org/docs/ref_builtins_node.html">
<link rel="canonical" href="https://freemarker.apache.org/docs/ref_builtins_node.html">
<link rel="icon" href="favicon.png" type="image/png">
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:500,700,400,300|Droid+Sans+Mono">
<link rel="stylesheet" type="text/css" href="docgen-resources/docgen.min.css?1707770044859">
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/cookie-bar/cookiebar-latest.min.js"></script>
</head>
<body itemscope itemtype="https://schema.org/Code">
<meta itemprop="url" content="https://freemarker.apache.org/docs/">
<meta itemprop="name" content="Apache FreeMarker Manual">
<!--[if lte IE 9]>
<div class="oldBrowserWarning" style="display: block">
Unsupported web browser - Use a modern browser to view this website!
</div>
<![endif]--> <div class="oldBrowserWarning">
Unsupported web browser - Use a modern browser to view this website!
</div>
<div class="header-top-bg"><div class="site-width header-top"><div id="hamburger-menu" role="button"></div> <div class="logo">
<a href="https://freemarker.apache.org" role="banner"><img itemprop="image" src="logo.png" alt="FreeMarker"></a> </div>
<ul class="tabs"><li><a href="https://freemarker.apache.org/">Home</a></li><li class="current"><a href="index.html">Manual</a></li><li><a class="external" href="api/index.html">Java API</a></li></ul><ul class="secondary-tabs"><li><a class="tab icon-heart" href="https://freemarker.apache.org/contribute.html" title="Contribute"><span>Contribute</span></a></li><li><a class="tab icon-bug" href="https://issues.apache.org/jira/projects/FREEMARKER" title="Report a Bug"><span>Report a Bug</span></a></li><li><a class="tab icon-download" href="https://freemarker.apache.org/freemarkerdownload.html" title="Download"><span>Download</span></a></li></ul></div></div><div class="header-bottom-bg"><div class="site-width search-row"><a href="index.html" class="navigation-header">Manual</a><div class="navigation-header"></div><form method="get" class="search-form" action="search-results.html"><fieldset><legend class="sr-only">Search form</legend><label for="search-field" class="sr-only">Search query</label><input id="search-field" name="q" type="search" class="search-input" placeholder="Search" spellcheck="false" autocorrect="off" autocomplete="off"><button type="submit" class="search-btn"><span class="sr-only">Search</span></button></fieldset></form></div><div class="site-width breadcrumb-row"> <div class="breadcrumbs">
<ul class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList"><li class="step-0" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="index.html"><span itemprop="name">Apache FreeMarker Manual</span></a></li><li class="step-1" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref.html"><span itemprop="name">Template Language Reference</span></a></li><li class="step-2" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref_builtins.html"><span itemprop="name">Built-in Reference</span></a></li><li class="step-3" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref_builtins_node.html"><span itemprop="name">Built-ins for nodes (for XML)</span></a></li></ul> </div>
<div class="bookmarks" title="Bookmarks"><span class="sr-only">Bookmarks:</span><ul><li><a href="alphaidx.html">Alpha. index</a></li><li><a href="gloss.html">Glossary</a></li><li><a href="dgui_template_exp.html#exp_cheatsheet">Expressions</a></li><li><a href="ref_builtins_alphaidx.html">?builtins</a></li><li><a href="ref_directive_alphaidx.html">#directives</a></li><li><a href="ref_specvar.html">.spec_vars</a></li><li><a href="app_faq.html">FAQ</a></li></ul></div></div></div> <div class="main-content site-width">
<div class="content-wrapper">
<div id="table-of-contents-wrapper" class="col-left">
<script>var breadcrumb = ["Apache FreeMarker Manual","Template Language Reference","Built-in Reference","Built-ins for nodes (for XML)"];</script>
<script src="toc.js?1707770044859"></script>
<script src="docgen-resources/main.min.js?1707770044859"></script>
</div>
<div class="col-right"><div class="page-content"><div class="page-title"><div class="pagers top"><a class="paging-arrow previous" href="ref_builtins_hash.html"><span>Previous</span></a><a class="paging-arrow next" href="ref_builtins_loop_var.html"><span>Next</span></a></div><div class="title-wrapper">
<h1 class="content-header header-section1" id="ref_builtins_node" itemprop="headline">Built-ins for nodes (for XML)</h1>
</div></div><div class="page-menu">
<div class="page-menu-title">Page Contents</div>
<ul><li><a class="page-menu-link" href="#ref_builtin_ancestors" data-menu-target="ref_builtin_ancestors">ancestors</a></li><li><a class="page-menu-link" href="#ref_builtin_children" data-menu-target="ref_builtin_children">children</a></li><li><a class="page-menu-link" href="#ref_builtin_node_name" data-menu-target="ref_builtin_node_name">node_name</a></li><li><a class="page-menu-link" href="#ref_builtin_next_sibling" data-menu-target="ref_builtin_next_sibling">next_sibling</a></li><li><a class="page-menu-link" href="#ref_builtin_node_namespace" data-menu-target="ref_builtin_node_namespace">node_namespace</a></li><li><a class="page-menu-link" href="#ref_builtin_node_type" data-menu-target="ref_builtin_node_type">node_type</a></li><li><a class="page-menu-link" href="#ref_builtin_parent" data-menu-target="ref_builtin_parent">parent</a></li><li><a class="page-menu-link" href="#ref_builtin_previous_sibling" data-menu-target="ref_builtin_previous_sibling">previous_sibling</a></li><li><a class="page-menu-link" href="#ref_builtin_root" data-menu-target="ref_builtin_root">root</a></li></ul> </div><p>Note that the variables returned by these built-ins are
generated by the node variable implementation it is used with. This
means that the returned variables can have extra features in
additional to what it stated here, for example, with the <a href="xgui_expose_dom.html">XML DOM nodes</a> the sequence retuned by
the <code class="inline-code">children</code> built-in also can be used as hash and
maybe as string, as it is described in the <a href="xgui.html">part
about XML processing</a>.</p>
<h2 class="content-header header-section2" id="ref_builtin_ancestors">ancestors</h2>
<p>A sequence that contains all the node&#39;s ancestors, starting
with the immediate parent and ending with the root node. The result
of this built-in is also a method, by which you can filter the
result with the <a href="gloss.html#gloss.fullQualifiedName">full-qualified name</a> of the
node. For example as <code class="inline-code">node?ancestors(&quot;section&quot;)</code> to
get the sequence of all ancestors with name
<code class="inline-code">section</code>.</p>
<h2 class="content-header header-section2" id="ref_builtin_children">children</h2>
<p>A sequence that contains all of this node&#39;s child nodes (i.e.
immediate descendant nodes).</p>
<p>XML: This is almost the same as special hash key
<code class="inline-code">*</code>, except that it returns all nodes, not only
elements. So the possible children are element nodes, text nodes,
comment nodes, processing instruction nodes, etc. but
<em>not</em> attribute nodes. Attribute nodes are
excluded from the sequence.</p>
<h2 class="content-header header-section2" id="ref_builtin_node_name">node_name</h2>
<p>Returns the string that is used to determine what user-defined
directive to invoke to handle this node when it is
"visited". See: the <a href="ref_directive_visit.html#ref.directive.visit">visit</a> and <a href="ref_directive_visit.html#ref.directive.recurse">recurse</a> directives.</p>
<p>XML: If the node is an element or attribute, then the string
will be the local (prefix free) name of the element or attribute.
Otherwise the name usually starts with <code class="inline-code">@</code> followed
by the node type. See <a href="xgui_imperative_formal.html#misc.xguiTable">this
table</a>. Note that this node name is not the same as the node
name returned in the DOM API; the goal of FreeMarker node names is
to give the name of the used-defined directive that will process the
node.</p>
<h2 class="content-header header-section2" id="ref_builtin_next_sibling">next_sibling</h2>
<div class="callout note">
<strong class="callout-label">Note:</strong>
<p>This built-in is only available since 2.3.26</p>
</div>
<p>Returns the following sibling node of the node. (Two nodes in
a tree are said to be siblings if they are on the same level and are
directly next to each other.) If there&#39;s no such node, the
expression
<code class="inline-code"><em class="code-color">node</em>?next_sibling??</code>
evaluates to <code class="inline-code">false</code>.</p>
<p>XML: Note that the value returned by this built-in is also a
sequence of length 1 (same as the result of some XPath expressions),
however if there&#39;s no next sibling, the result is a missing value
(null) instead of an empty sequence. Also note that for XML element
nodes you can also use
<code class="inline-code"><em class="code-color">node</em>.@@next_sibling_element</code>,
which is practical if you want to ignore the whitespace that
separates two apparently sibling elements; see more <a href="xgui_imperative_formal.html">here...</a></p>
<div class="callout note">
<strong class="callout-label">Note:</strong>
<p>For custom node implementations this built-in is only
supported if that implements the
<code class="inline-code">freemarker.template.TemplateNodeModelEx</code>
interface.</p>
</div>
<h2 class="content-header header-section2" id="ref_builtin_node_namespace">node_namespace</h2>
<p>Returns the namespace string of the node. FreeMarker does not
define the exact meaning of node namespace; it depends on what your
node variables are modeling. It&#39;s possible that a node doesn&#39;t have
any node namespace defined. In this case, the built-in should
evaluate to undefined variable (i.e.
<code class="inline-code">node?<em class="code-color">node_namespace</em>??</code>
is <code class="inline-code">false</code>), so you can&#39;t use the returned
value.</p>
<p>XML: In the case of XML, it&#39;s the XML namespace URI (such as
<code class="inline-code">&quot;http://www.w3.org/1999/xhtml&quot;</code>). If an element or
attribute node does not use XML namespace, then this built-in
evaluates to an empty string. For other XML nodes this built-in
always return undefined variable.</p>
<h2 class="content-header header-section2" id="ref_builtin_node_type">node_type</h2>
<p>A string that describes the type of the node. FreeMarker does
not define the exact meaning of node type; it depends on what your
variables are modeling. It&#39;s possible that a node doesn&#39;t support
node type at all. In this case, the built-in evaluates to an
undefined value, so you can&#39;t use the returned value. (You can still
check if a node supports the type property with
<code class="inline-code"><em class="code-color">node</em>?node_type??</code>.)</p>
<p>XML: The possible values are: <code class="inline-code">&quot;attribute&quot;</code>,
<code class="inline-code">&quot;text&quot;</code>, <code class="inline-code">&quot;comment&quot;</code>,
<code class="inline-code">&quot;document_fragment&quot;</code>,
<code class="inline-code">&quot;document&quot;</code>, <code class="inline-code">&quot;document_type&quot;</code>,
<code class="inline-code">&quot;element&quot;</code>, <code class="inline-code">&quot;entity&quot;</code>,
<code class="inline-code">&quot;entity_reference&quot;</code>,
<code class="inline-code">&quot;notation&quot;</code>, <code class="inline-code">&quot;pi&quot;</code>. Note that a
there is no <code class="inline-code">&quot;cdata&quot;</code> type, because CDATA is
considered as plain text node.</p>
<h2 class="content-header header-section2" id="ref_builtin_parent">parent</h2>
<p>Returns the node that is this node&#39;s immediate parent in the
node tree. The root node has no parent node, so for the root node,
the expression
<code class="inline-code"><em class="code-color">node</em>?parent??</code>
evaluates to <code class="inline-code">false</code>.</p>
<p>XML: Note that the value returned by this built-in is also a
sequence (same as the result of XPath expression
<code class="inline-code">..</code>, when you write
<code class="inline-code">someNode[&quot;..&quot;]</code>), however if there&#39;s no parent,
the result is a missing value (null) instead of an empty sequence.
Also note that for attribute nodes, it returns the element the
attribute belongs to, despite that attribute nodes are not counted
as children of the element.</p>
<h2 class="content-header header-section2" id="ref_builtin_previous_sibling">previous_sibling</h2>
<div class="callout note">
<strong class="callout-label">Note:</strong>
<p>This built-in is only available since 2.3.26</p>
</div>
<p>Returns the previous sibling node of the node. Apart from the
direction, this is the same as <code class="inline-code">next_sibling</code>, so
see more details <a href="#ref_builtin_next_sibling">there...</a></p>
<div class="callout note">
<strong class="callout-label">Note:</strong>
<p>For custom node implementations this built-in is only
supported if that implements the
<code class="inline-code">freemarker.template.TemplateNodeModelEx</code>
interface.</p>
</div>
<h2 class="content-header header-section2" id="ref_builtin_root">root</h2>
<p>The node that is the root of the tree of nodes to which this
node belongs.</p>
<p>XML: According to W3C, the root of an XML document is not the
topmost element node, but the document itself, which is the parent
of the topmost element. For example, if you want to get the topmost
<em>element</em> of the XML (the so called
"document element"; do not mix it with the
"document"), which is called <code class="inline-code">foo</code>,
then you have to write <code class="inline-code">someNode?root.foo</code>. If you
write just <code class="inline-code">someNode?root</code>, then you get the
document itself, and not the document element.</p>
<div class="bottom-pagers-wrapper"><div class="pagers bottom"><a class="paging-arrow previous" href="ref_builtins_hash.html"><span>Previous</span></a><a class="paging-arrow next" href="ref_builtins_loop_var.html"><span>Next</span></a></div></div></div></div> </div>
</div>
<div class="site-footer"><div class="site-width"><div class="footer-top"><div class="col-left sitemap"><div class="column"><h3 class="column-header">Overview</h3><ul><li><a href="https://freemarker.apache.org/">What is FreeMarker?</a></li><li><a href="https://freemarker.apache.org/freemarkerdownload.html">Download</a></li><li><a href="app_versions.html">Version history</a></li><li><a href="app_faq.html">FAQ</a></li><li><a itemprop="license" href="app_license.html">License</a></li><li><a href="https://privacy.apache.org/policies/privacy-policy-public.html">Privacy policy</a></li></ul></div><div class="column"><h3 class="column-header">Often used / Reference</h3><ul><li><a href="https://try.freemarker.apache.org/">Try template online</a></li><li><a href="dgui_template_exp.html#exp_cheatsheet">Expressions cheatsheet</a></li><li><a href="ref_directive_alphaidx.html">#directives</a></li><li><a href="ref_builtins_alphaidx.html">?built_ins</a></li><li><a href="ref_specvar.html">.special_vars</a></li><li><a href="api/freemarker/core/Configurable.html#setSetting-java.lang.String-java.lang.String-">Configuration settings</a></li></ul></div><div class="column"><h3 class="column-header">Community</h3><ul><li><a href="https://github.com/apache/freemarker">Github project page</a></li><li><a href="https://issues.apache.org/jira/projects/FREEMARKER">Report a bug</a></li><li><a href="https://freemarker.apache.org/report-security-vulnerabilities.html">Report security vulnerability</a></li><li><a href="https://stackoverflow.com/questions/ask?tags=freemarker">Get help on StackOverflow</a></li><li><a href="https://twitter.com/freemarker">Announcements on Twitter</a></li><li><a href="https://freemarker.apache.org/mailing-lists.html">Discuss on mailing lists</a></li></ul></div></div><div class="col-right"><ul class="social-icons"><li><a class="github" href="https://github.com/apache/freemarker">Github</a></li><li><a class="twitter" href="https://twitter.com/freemarker">Twitter</a></li><li><a class="stack-overflow" href="https://stackoverflow.com/questions/ask?tags=freemarker">Stack Overflow</a></li></ul><a class="xxe" href="http://www.xmlmind.com/xmleditor/" rel="nofollow" title="Edited with XMLMind XML Editor"><span>Edited with XMLMind XML Editor</span></a></div></div><div class="footer-bottom"> <p class="last-generated">
Last generated:
<time itemprop="dateModified" datetime="2024-02-12T20:34:04Z" title="Monday, February 12, 2024 at 8:34:04 PM Greenwich Mean Time">2024-02-12 20:34:04 GMT</time>, for Freemarker 2.3.32 </p>
<p class="copyright">
© <span itemprop="copyrightYear">1999</span>–2024
<a itemtype="http://schema.org/Organization" itemprop="copyrightHolder" href="https://apache.org/">The Apache Software Foundation</a>. Apache FreeMarker, FreeMarker, Apache Incubator, Apache, the Apache FreeMarker logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners. </p>
</div></div></div></body>
</html>