net.sf.saxon.style
Class XSLTemplate

java.lang.Object
  extended by net.sf.saxon.tree.linked.NodeImpl
      extended by net.sf.saxon.tree.linked.ElementImpl
          extended by net.sf.saxon.style.StyleElement
              extended by net.sf.saxon.style.XSLTemplate
All Implemented Interfaces:
Serializable, Source, SourceLocator, LocationProvider, SaxonLocator, PullEvent, Container, FingerprintedNode, Item, MutableNodeInfo, NamespaceResolver, NodeInfo, ValueRepresentation, StylesheetProcedure, InstructionInfo, SiblingCountingNode, Locator

public final class XSLTemplate
extends StyleElement
implements StylesheetProcedure

An xsl:template element in the style sheet.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class net.sf.saxon.style.StyleElement
ACTION_COMPILE, ACTION_FIXUP, ACTION_OPTIMIZE, ACTION_PROCESS_ATTRIBUTES, ACTION_TYPECHECK, ACTION_VALIDATE, actionsCompleted, defaultCollationName, defaultXPathNamespace, extensionNamespaces, REPORT_ALWAYS, REPORT_IF_INSTANTIATED, REPORT_UNLESS_FALLBACK_AVAILABLE, REPORT_UNLESS_FORWARDS_COMPATIBLE, reportingCircumstances, staticContext, validationError, version
 
Fields inherited from class net.sf.saxon.tree.linked.NodeImpl
NODE_LETTER
 
Fields inherited from interface net.sf.saxon.om.NodeInfo
ALL_NAMESPACES, EMPTY_NAMESPACE_LIST, IS_DTD_TYPE, IS_NILLED, LOCAL_NAMESPACES, NO_NAMESPACES
 
Constructor Summary
XSLTemplate()
           
 
Method Summary
protected  void addChild(NodeImpl node, int index)
          Add a child node to this node.
 void compact(int size)
          Compact the space used by this node
 Expression compile(Executable exec, Declaration decl)
          Compile: creates the executable form of the template
protected  AxisIterator enumerateChildren(NodeTest test)
          Get an enumeration of the children of this node
 Template getCompiledTemplate()
          Get the compiled template
 int getConstructType()
          Get the type of construct.
 NodeInfo getFirstChild()
          Get the first child node of the element
 NodeInfo getLastChild()
          Get the last child node of the element
protected  NodeImpl getNthChild(int n)
          Get the nth child node of the element (numbering from 0)
 int getNumberOfChildren()
          Determine how many children the node has
protected  int getRawSequenceNumber()
           
protected  ItemType getReturnedItemType()
          Determine the type of item returned by this template
protected  long getSequenceNumber()
          Get the node sequence number (in document order).
 SlotManager getSlotManager()
          Get associated Procedure (for details of stack frame)
 String getStringValue()
          Return the string-value of the node, that is, the concatenation of the character content of all descendent elements and text nodes.
 CharSequence getStringValueCS()
          Get the value of the item as a CharSequence.
 StructuredQName getTemplateName()
          Return the name of this template.
 boolean hasChildNodes()
          Determine if the node has any children.
protected  void index(Declaration decl, PrincipalStylesheetModule top)
          Method supplied by declaration elements to add themselves to a stylesheet-level index
 void insertChildren(NodeInfo[] source, boolean atStart, boolean inherit)
          Insert a sequence of nodes as children of this node.
protected  void insertChildrenAt(NodeInfo[] source, int index, boolean inherit)
          Insert children before or after a given existing child
 boolean isDeclaration()
          Ask whether this node is a declaration, that is, a permitted child of xsl:stylesheet (including xsl:include and xsl:import).
protected  boolean isPermittedChild(StyleElement child)
          Specify that xsl:param is a permitted child
 boolean markTailCalls()
          Mark tail-recursive calls on templates and functions.
protected  boolean mayContainParam(String attName)
          Determine whether this type of element is allowed to contain an xsl:param element
 boolean mayContainSequenceConstructor()
          Determine whether this type of element is allowed to contain a template-body
 void optimize(Declaration declaration)
          This method is a bit of a misnomer, because it does more than invoke optimization of the template body.
 void postValidate()
          Hook to allow additional validation of a parent element immediately after its children have been validated.
 void prepareAttributes()
          Set the attribute list for the element.
 void register(Declaration declaration)
          Registers the template rule with each Mode that it belongs to.
protected  void removeChild(NodeImpl child)
          Remove a given child
protected  void replaceChildrenAt(NodeInfo[] source, int index, boolean inherit)
          Replace child at a given index by new children
protected  void setChildren(Object children)
          Set the children of this node
protected  void setRawSequenceNumber(int seq)
           
 void validate(Declaration decl)
          Check that the stylesheet element is valid.
 
Methods inherited from class net.sf.saxon.style.StyleElement
allocateLocationId, allocatePatternSlots, allocateSlots, bindVariable, checkEmpty, checkSortComesFirst, checkTopLevel, checkUnknownAttribute, compileError, compileError, compileError, compileError, compileSequenceConstructor, compileWarning, compileWarning, definesExcludedNamespace, definesExtensionElement, fallbackProcessing, fixupReferences, forwardsCompatibleModeIsEnabled, getAttributeSets, getAttributeValue, getColumnNumber, getCommonChildItemType, getContainerGranularity, getContainingSlotManager, getContainingStylesheet, getDefaultCollationName, getDefaultXPathNamespace, getEffectiveVersion, getExecutable, getHostLanguage, getLastChildInstruction, getLineNumber, getLocationProvider, getNamespaceResolver, getObjectName, getPreparedStylesheet, getPrincipalStylesheetModule, getProcessorVersion, getProperties, getProperty, getSchemaType, getStaticContext, getSystemId, getTypeAnnotation, getWithParamInstructions, isActionCompleted, isExcludedNamespace, isExplaining, isExtensionNamespace, isInstruction, issueWarning, issueWarning, isTopLevel, isXslt30Processor, makeAttributeValueTemplate, makeExpression, makeExpressionVisitor, makeNamespaceContext, makePattern, makeQName, makeSequenceType, makeSortKeys, makeTraceInstruction, mayContainFallback, processAllAttributes, processAttributes, processDefaultCollationAttribute, processDefaultXPathNamespaceAttribute, processExcludedNamespaces, processExtensionElementAttribute, processStandardAttributes, processVersionAttribute, reportAbsence, seesAvuncularVariables, setActionCompleted, setObjectName, setValidationError, substituteFor, typeCheck, typeCheck, undeclaredNamespaceError, validateChildren, validateSubtree, xPath10ModeIsEnabled
 
Methods inherited from class net.sf.saxon.tree.linked.ElementImpl
addAttribute, addNamespace, copy, delete, fixupInsertedNamespaces, generateId, getAttributeList, getAttributeValue, getAttributeValue, getBaseURI, getColumnNumber, getDeclaredNamespaces, getDocumentRoot, getInScopeNamespaceCodes, getLineNumber, getNameCode, getNamespaceList, getNodeKind, getPrefixForURI, getRoot, getSystemId, getTypeAnnotation, getURICodeForPrefix, getURICodeForPrefixCode, getURIForPrefix, gsetAttributeCollection, initialise, isId, isNilled, iteratePrefixes, removeAttribute, removeTypeAnnotation, rename, replaceStringValue, setAttributeList, setLineAndColumn, setLocation, setNameCode, setNamespaceDeclarations, setNamespaceList, setSystemId, setTypeAnnotation
 
Methods inherited from class net.sf.saxon.tree.linked.NodeImpl
atomize, compareOrder, equals, getConfiguration, getDisplayName, getDocumentNumber, getFingerprint, getLocalPart, getNamePool, getNextInDocument, getNextSibling, getParent, getPhysicalRoot, getPrefix, getPreviousInDocument, getPreviousSibling, getPublicId, getRawParent, getSiblingPosition, getTypedValue, getURI, insertSiblings, isDeleted, isIdref, isSameNodeInfo, iterateAxis, iterateAxis, newBuilder, replace, setRawParent, setSiblingPosition
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.saxon.trace.InstructionInfo
getLineNumber, getSystemId
 
Methods inherited from interface org.xml.sax.Locator
getColumnNumber, getPublicId
 
Methods inherited from interface javax.xml.transform.SourceLocator
getColumnNumber, getPublicId
 
Methods inherited from interface net.sf.saxon.om.NodeInfo
hashCode
 

Constructor Detail

XSLTemplate

public XSLTemplate()
Method Detail

isDeclaration

public boolean isDeclaration()
Ask whether this node is a declaration, that is, a permitted child of xsl:stylesheet (including xsl:include and xsl:import).

Overrides:
isDeclaration in class StyleElement
Returns:
true for this element

mayContainSequenceConstructor

public boolean mayContainSequenceConstructor()
Determine whether this type of element is allowed to contain a template-body

Overrides:
mayContainSequenceConstructor in class StyleElement
Returns:
true: yes, it may contain a template-body

mayContainParam

protected boolean mayContainParam(String attName)
Description copied from class: StyleElement
Determine whether this type of element is allowed to contain an xsl:param element

Overrides:
mayContainParam in class StyleElement
Parameters:
attName - if null, the method tests whether an xsl:param child is allowed. If non-null, it tests whether an xsl:param child with the given attribute name is allowed
Returns:
true if this element is allowed to contain an xsl:param

isPermittedChild

protected boolean isPermittedChild(StyleElement child)
Specify that xsl:param is a permitted child

Overrides:
isPermittedChild in class StyleElement
Parameters:
child - the child that may or may not be permitted
Returns:
true if the child is permitted.

getTemplateName

public StructuredQName getTemplateName()
Return the name of this template. Note that this may be called before prepareAttributes has been called.

Returns:
the name of the template as a Structured QName.

getReturnedItemType

protected ItemType getReturnedItemType()
Determine the type of item returned by this template

Overrides:
getReturnedItemType in class StyleElement
Returns:
the item type returned

prepareAttributes

public void prepareAttributes()
                       throws XPathException
Description copied from class: StyleElement
Set the attribute list for the element. This is called to process the attributes (note the distinction from processAttributes in the superclass). Must be supplied in a subclass

Specified by:
prepareAttributes in class StyleElement
Throws:
XPathException

validate

public void validate(Declaration decl)
              throws XPathException
Description copied from class: StyleElement
Check that the stylesheet element is valid. This is called once for each element, after the entire tree has been built. As well as validation, it can perform first-time initialisation. The default implementation does nothing; it is normally overriden in subclasses.

Overrides:
validate in class StyleElement
Throws:
XPathException

postValidate

public void postValidate()
                  throws XPathException
Description copied from class: StyleElement
Hook to allow additional validation of a parent element immediately after its children have been validated.

Overrides:
postValidate in class StyleElement
Throws:
XPathException

index

protected void index(Declaration decl,
                     PrincipalStylesheetModule top)
              throws XPathException
Description copied from class: StyleElement
Method supplied by declaration elements to add themselves to a stylesheet-level index

Overrides:
index in class StyleElement
Parameters:
decl - the Declaration being indexed. (This corresponds to the StyleElement object except in cases where one module is imported several times with different precedence.)
top - the outermost XSLStylesheet element
Throws:
XPathException

markTailCalls

public boolean markTailCalls()
Mark tail-recursive calls on templates and functions.

Overrides:
markTailCalls in class StyleElement
Returns:
true if one or more tail calls were identified

compile

public Expression compile(Executable exec,
                          Declaration decl)
                   throws XPathException
Compile: creates the executable form of the template

Specified by:
compile in class StyleElement
Parameters:
exec - the Executable
decl - the containing top-level declaration, for example xsl:function or xsl:template
Returns:
either a ComputedExpression, or null. The value null is returned when compiling an instruction that returns a no-op, or when compiling a top-level object such as an xsl:template that compiles into something other than an instruction.
Throws:
XPathException

register

public void register(Declaration declaration)
              throws XPathException
Registers the template rule with each Mode that it belongs to.

Parameters:
declaration - Associates this template with a stylesheet module (in principle an xsl:template element can be in a document that is imported more than once; these are separate declarations)
Throws:
XPathException

optimize

public void optimize(Declaration declaration)
              throws XPathException
This method is a bit of a misnomer, because it does more than invoke optimization of the template body. In particular, it also registers the template rule with each Mode that it belongs to.

Specified by:
optimize in interface StylesheetProcedure
Parameters:
declaration - Associates this template with a stylesheet module (in principle an xsl:template element can be in a document that is imported more than once; these are separate declarations)
Throws:
XPathException

getSlotManager

public SlotManager getSlotManager()
Get associated Procedure (for details of stack frame)

Specified by:
getSlotManager in interface StylesheetProcedure
Returns:
the associated SlotManager object

getCompiledTemplate

public Template getCompiledTemplate()
Get the compiled template

Returns:
the compiled template

getConstructType

public int getConstructType()
Get the type of construct. This will be a constant in class Location. This method is part of the InstructionInfo interface

Specified by:
getConstructType in interface InstructionInfo
Overrides:
getConstructType in class StyleElement
Returns:
an integer identifying the kind of construct

getSequenceNumber

protected final long getSequenceNumber()
Get the node sequence number (in document order). Sequence numbers are monotonic but not consecutive. In the current implementation, parent nodes (elements and document nodes) have a zero least-significant word, while namespaces, attributes, text nodes, comments, and PIs have the top word the same as their owner and the bottom half reflecting their relative position. For nodes added by XQUery Update, the sequence number is -1L

Overrides:
getSequenceNumber in class NodeImpl
Returns:
the sequence number if there is one, or -1L otherwise.

getRawSequenceNumber

protected final int getRawSequenceNumber()

setRawSequenceNumber

protected final void setRawSequenceNumber(int seq)

setChildren

protected final void setChildren(Object children)
Set the children of this node

Parameters:
children - null if there are no children, a single NodeInfo if there is one child, an array of NodeInfo if there are multiple children

hasChildNodes

public final boolean hasChildNodes()
Determine if the node has any children.

Specified by:
hasChildNodes in interface NodeInfo
Overrides:
hasChildNodes in class NodeImpl
Returns:
true if the node has any children, false if the node has no children.

getNumberOfChildren

public final int getNumberOfChildren()
Determine how many children the node has

Returns:
the number of children of this parent node

enumerateChildren

protected final AxisIterator enumerateChildren(NodeTest test)
Get an enumeration of the children of this node

Parameters:
test - A NodeTest to be satisfied by the child nodes, or null if all child node are to be returned
Returns:
an iterator over the children of this node

getFirstChild

public final NodeInfo getFirstChild()
Get the first child node of the element

Overrides:
getFirstChild in class NodeImpl
Returns:
the first child node of the required type, or null if there are no children

getLastChild

public final NodeInfo getLastChild()
Get the last child node of the element

Overrides:
getLastChild in class NodeImpl
Returns:
the last child of the element, or null if there are no children

getNthChild

protected final NodeImpl getNthChild(int n)
Get the nth child node of the element (numbering from 0)

Parameters:
n - identifies the required child
Returns:
the last child of the element, or null if there is no n'th child

removeChild

protected void removeChild(NodeImpl child)
Remove a given child

Parameters:
child - the child to be removed

getStringValue

public String getStringValue()
Return the string-value of the node, that is, the concatenation of the character content of all descendent elements and text nodes.

Returns:
the accumulated character content of the element, including descendant elements.
See Also:
Item.getStringValueCS()

getStringValueCS

public CharSequence getStringValueCS()
Description copied from class: NodeImpl
Get the value of the item as a CharSequence. This is in some cases more efficient than the version of the method that returns a String.

Specified by:
getStringValueCS in interface Item
Specified by:
getStringValueCS in interface ValueRepresentation
Overrides:
getStringValueCS in class NodeImpl
Returns:
the string value of the item
See Also:
Item.getStringValue()

addChild

protected void addChild(NodeImpl node,
                        int index)
Add a child node to this node. For system use only. Note: normalizing adjacent text nodes is the responsibility of the caller.

Parameters:
node - the node to be added as a child of this node. This must be an instance of NodeImpl. It will be modified as a result of this call (by setting its parent property and sibling position)
index - the position where the child is to be added

insertChildren

public void insertChildren(NodeInfo[] source,
                           boolean atStart,
                           boolean inherit)
Insert a sequence of nodes as children of this node.

This method takes no action unless the target node is a document node or element node. It also takes no action in respect of any supplied nodes that are not elements, text nodes, comments, or processing instructions.

The supplied nodes will form the new children. Adjacent text nodes will be merged, and zero-length text nodes removed. The supplied nodes may be modified in situ, for example to change their parent property and to add namespace bindings, or they may be copied, at the discretion of the implementation.

Specified by:
insertChildren in interface MutableNodeInfo
Overrides:
insertChildren in class NodeImpl
Parameters:
source - the nodes to be inserted. The implementation determines what implementation classes of node it will accept; this implementation will accept text, comment, and processing instruction nodes belonging to any implementation, but elements must be instances of ElementImpl. The supplied nodes will be modified in situ, for example to change their parent property and to add namespace bindings, if they are instances of ElementImpl; otherwise they will be copied. If the nodes are copied, then on return the supplied source array will contain the copy rather than the original.
atStart - true if the new nodes are to be inserted before existing children; false if they are to be inserted after existing children
inherit - true if the inserted nodes are to inherit the namespaces of their new parent; false if such namespaces are to be undeclared
Throws:
IllegalArgumentException - if the supplied nodes use a node implementation that this implementation does not accept.

insertChildrenAt

protected void insertChildrenAt(NodeInfo[] source,
                                int index,
                                boolean inherit)
Insert children before or after a given existing child

Parameters:
source - the children to be inserted. We allow any kind of text, comment, or processing instruction node, but element nodes must be instances of this NodeInfo implementation.
index - the position before which they are to be inserted: 0 indicates insertion before the first child, 1 insertion before the second child, and so on.
inherit - true if the inserted nodes are to inherit the namespaces that are in-scope for their new parent; false if such namespaces should be undeclared on the children

replaceChildrenAt

protected void replaceChildrenAt(NodeInfo[] source,
                                 int index,
                                 boolean inherit)
Replace child at a given index by new children

Parameters:
source - the children to be inserted
index - the position at which they are to be inserted: 0 indicates replacement of the first child, replacement of the second child, and so on. The effect is undefined if index is out of range
inherit - set to true if the new child elements are to inherit the in-scope namespaces of their new parent
Throws:
IllegalArgumentException - if any of the replacement nodes is not an element, text, comment, or processing instruction node

compact

public void compact(int size)
Compact the space used by this node

Parameters:
size - the number of actual children


Copyright (c) 2004-2010 Saxonica Limited. All rights reserved.