|
Exposing an XML Document to a TemplateThe class TemplateScalarModelWhen used as a scalar, the node list will render the XML fragment that represents its contained nodes. This makes it handy for use in XML-to-XML transforming templates. TemplateCollectionModelWhen used as a collection in a TemplateSequenceModelWhen used as a sequence, it will return the i-th node as a new node list consisting of the single requested node. TemplateHashModelWhen used as a hash, it is basically used to traverse children. That is, if
you have a node list named "book" that wraps an element node with several chapters,
then the The hash defines several "magic keys" as well. All these keys start with an
underscore. The most notable is the "_text" key which retrieves the text of the
node: TemplateMethodModelWhen used as a method model, it returns a node list that is the result of
evaluating an XPath expression on the current contents of the node list. For
this feature to work, you must have Namespace handlingFor purposes of traversal of children elements that have namespace-scoped names, you can register namespace prefixes with the node list. You can do it either in Java, calling the public void registerNamespace(String prefix, String uri); method, or inside a template using the ${nodelist._registerNamespace(prefix, uri)} syntax. From there on, you can refer to children elements in the namespace denoted by the particular URI through the syntax nodelist["prefix:localName"] and nodelist["@prefix:localName"] Namespaces registered with a node list are propagated to all node lists that are derived from the original node list. Note also that namespaces are matched by their URI only, so you can safely use a prefix for a namespace inside your template that differs from the prefix in the actual XML document - a prefix is just a local alias for the URI both in the template and in the XML document. |
|