Package net.sf.saxon.style
Class XSLTemplate
- java.lang.Object
-
- All Implemented Interfaces:
javax.xml.transform.Source,javax.xml.transform.SourceLocator,GroundedValue,Item,MutableNodeInfo,NamespaceResolver,NodeInfo,Sequence,Location,StylesheetComponent,SteppingNode<NodeImpl>,SiblingCountingNode,org.xml.sax.Locator
public final class XSLTemplate extends StyleElement implements StylesheetComponent
An xsl:template element in the style sheet.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.sf.saxon.style.StyleElement
StyleElement.OnFailure
-
-
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, defaultMode, defaultXPathNamespace, expandText, extensionNamespaces, 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
IS_DTD_TYPE, IS_NILLED
-
-
Constructor Summary
Constructors Constructor Description XSLTemplate()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidallocatePatternSlotNumbers()Allocate slot numbers to any local variables declared within a predicate within the match patternvoidcheckCompatibility(Component component)Check the compatibility of this component with another component that it is overridingvoidcompileDeclaration(Compilation compilation, ComponentDeclaration decl)Compile: creates the executable form of the templatevoidcompileTemplateRule(Compilation compilation, Expression body, ComponentDeclaration decl)voidgenerateByteCode(Optimizer opt)Generate byte code for the template (if appropriate)NamedTemplategetActor()Get the corresponding NamedTemplate object that results from the compilation of this StylesheetComponentjava.util.Set<Mode>getApplicableModes()Get the modes to which this template rule appliesNamedTemplategetCompiledNamedTemplate()Get the compiled templateItemTypegetContextItemTypeForTemplateRule()PatterngetMatch()StructuredQName[]getModeNames()Return the list of mode names to which this template rule is applicable.XSLLocalParamgetParam(StructuredQName name)ItemTypegetRequiredContextItemType()SlotManagergetSlotManager()Get associated Procedure (for details of stack frame)SymbolicNamegetSymbolicName()Get the symbolic name of the component, that is, the combination of the component kind and the qualified nameStructuredQNamegetTemplateName()Return the name of this template.java.util.Map<StructuredQName,TemplateRule>getTemplateRulesByMode()voidindex(ComponentDeclaration decl, PrincipalStylesheetModule top)Method supplied by declaration elements to add themselves to a stylesheet-level indexbooleanisDeclaration()Ask whether this node is a declaration, that is, a permitted child of xsl:stylesheet (including xsl:include and xsl:import).booleanisDeferredCompilation(Compilation compilation)Ask whether the compilation of the template should be deferredbooleanisMayOmitContextItem()booleanisOmniMode()Ask whether this is a template rule with mode="#allprotected booleanisPermittedChild(StyleElement child)Specify that xsl:param and xsl:context-item are permitted childrenprotected booleanisWithinDeclaredStreamableConstruct()voidjitCompile(Compilation compilation, ComponentDeclaration decl)Code executed when the template is first executed under JIT.booleanmarkTailCalls()Mark tail-recursive calls on templates and functions.protected booleanmayContainParam()Determine whether this type of element is allowed to contain an xsl:param elementbooleanmayContainSequenceConstructor()Determine whether this type of element is allowed to contain a template-bodyvoidoptimize(ComponentDeclaration declaration)This method is a bit of a misnomer, because it does more than invoke optimization of the template body.voidprepareAttributes()Set the attribute list for the element.voidprocessAllAttributes()Process the attributes of this element and all its childrenvoidregister(ComponentDeclaration declaration)Registers the template rule with each Mode that it belongs to.voidsetCompilation(Compilation compilation)voidsetContextItemRequirements(ItemType type, boolean mayBeOmitted, boolean absentFocus)Set the required context item type.voidvalidate(ComponentDeclaration decl)Check that the stylesheet element is valid.voidvalidateSubtree(ComponentDeclaration decl, boolean excludeStylesheet)Recursive walk through the stylesheet to validate all nodes-
Methods inherited from class net.sf.saxon.style.StyleElement
allocateLocation, bindLocalVariable, bindVariable, checkEmpty, checkTopLevel, checkUnknownAttribute, compile, compileError, compileError, compileError, compileError, compileError, compileError, compileErrorInAttribute, compileSequenceConstructor, compileSequenceConstructor, compileWarning, compileWarning, compileWarning, fixupReferences, generateId, getAttributeValue, getBaseURI, getBindingInformation, getCompilation, getConfiguration, getContainingPackage, getContainingSlotManager, getDeclaredVisibility, getDefaultCollationName, getDefaultXPathNamespace, getNamespaceResolver, getObjectName, getPackageData, getPrincipalStylesheetModule, getProperties, getSchemaType, getStaticContext, getStaticContext, getTypeAnnotation, getUsedPackage, getVisibility, getWithParamInstructions, getXslOriginal, hasImplicitBinding, invalidAttribute, isExtensionAttributeAllowed, isExtensionNamespace, isInstruction, isSchemaAware, issueWarning, issueWarning, isTopLevel, makeAttributeValueTemplate, makeExpression, makeExpressionVisitor, makeQName, makeRetainedStaticContext, makeSequenceType, mayContainFallback, postValidate, processBooleanAttribute, processStandardAttributes, processVersionAttribute, reportAbsence, requireSyntaxExtensions, seesAvuncularVariables, setObjectName, setValidationError, substituteFor, typeCheck, typeCheck, validateChildren, validateValidationAttribute
-
Methods inherited from class net.sf.saxon.tree.linked.ElementImpl
addAttribute, addNamespace, addNamespace, attributes, checkNotNamespaceSensitiveElement, copy, delete, fixupInsertedNamespaces, generateId, getAllNamespaces, getAttributeValue, getColumnNumber, getDeclaredNamespaces, getLineNumber, getNodeKind, getNodeName, getRoot, getSchemaType, getSystemId, getURIForPrefix, initialise, isId, isIdref, isInScopeNamespace, isNilled, iteratePrefixes, removeAttribute, removeNamespace, removeTypeAnnotation, rename, replaceStringValue, setAttributeInfo, setAttributes, setLocation, setNamespaceMap, setNilled, setNodeName, setSystemId, setTypeAnnotation
-
Methods inherited from class net.sf.saxon.tree.linked.ParentNodeImpl
addChild, children, compact, getFirstChild, getLastChild, getNthChild, getNumberOfChildren, getRawSequenceNumber, getSequenceNumber, getStringValue, getStringValueCS, hasChildNodes, insertChildren, iterateChildren, removeChild, replaceChildrenAt, setChildren, setRawSequenceNumber
-
Methods inherited from class net.sf.saxon.tree.linked.NodeImpl
atomize, compareOrder, effectiveBooleanValue, equals, getDisplayName, getFingerprint, getLocalPart, getNamePool, getNextInDocument, getNextSibling, getParent, getPhysicalRoot, getPrefix, getPreviousInDocument, getPreviousSibling, getRawParent, getSiblingPosition, getSuccessorElement, getTreeInfo, getURI, hasFingerprint, head, insertSiblings, isDeleted, iterateAxis, iterateAxis, newBuilder, replace, saveLocation, setRawParent, setSiblingPosition
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.om.GroundedValue
asIterable, concatenate, containsNode, materialize
-
Methods inherited from interface net.sf.saxon.om.Item
getLength, itemAt, iterate, reduce, subsequence
-
Methods inherited from interface net.sf.saxon.om.NodeInfo
children, equals, getGenre, getPublicId, hashCode, isSameNodeInfo, isStreamed, toShortString
-
Methods inherited from interface net.sf.saxon.om.Sequence
makeRepeatable
-
-
-
-
Method Detail
-
getActor
public NamedTemplate getActor()
Get the corresponding NamedTemplate object that results from the compilation of this StylesheetComponent- Specified by:
getActorin interfaceStylesheetComponent- Returns:
- the compiled ComponentCode
-
setCompilation
public void setCompilation(Compilation compilation)
- Overrides:
setCompilationin classStyleElement
-
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:
isDeclarationin classStyleElement- Returns:
- true for this element
-
isDeferredCompilation
public boolean isDeferredCompilation(Compilation compilation)
Ask whether the compilation of the template should be deferred- Parameters:
compilation- the compilation- Returns:
- true if compilation should be deferred
-
mayContainSequenceConstructor
public boolean mayContainSequenceConstructor()
Determine whether this type of element is allowed to contain a template-body- Overrides:
mayContainSequenceConstructorin classStyleElement- Returns:
- true: yes, it may contain a template-body
-
mayContainParam
protected boolean mayContainParam()
Description copied from class:StyleElementDetermine whether this type of element is allowed to contain an xsl:param element- Overrides:
mayContainParamin classStyleElement- Returns:
- true if this element is allowed to contain an xsl:param
-
isWithinDeclaredStreamableConstruct
protected boolean isWithinDeclaredStreamableConstruct()
- Overrides:
isWithinDeclaredStreamableConstructin classStyleElement
-
setContextItemRequirements
public void setContextItemRequirements(ItemType type, boolean mayBeOmitted, boolean absentFocus)
Set the required context item type. Used when there is an xsl:context-item child element- Parameters:
type- the required context item typemayBeOmitted- true if the context item may be absentabsentFocus- true if use=absent is specified
-
isPermittedChild
protected boolean isPermittedChild(StyleElement child)
Specify that xsl:param and xsl:context-item are permitted children- Overrides:
isPermittedChildin classStyleElement- 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.
-
getSymbolicName
public SymbolicName getSymbolicName()
Description copied from interface:StylesheetComponentGet the symbolic name of the component, that is, the combination of the component kind and the qualified name- Specified by:
getSymbolicNamein interfaceStylesheetComponent- Returns:
- the component's symbolic name
-
getRequiredContextItemType
public ItemType getRequiredContextItemType()
-
isMayOmitContextItem
public boolean isMayOmitContextItem()
-
checkCompatibility
public void checkCompatibility(Component component)
Description copied from interface:StylesheetComponentCheck the compatibility of this component with another component that it is overriding- Specified by:
checkCompatibilityin interfaceStylesheetComponent- Parameters:
component- the overridden component
-
getParam
public XSLLocalParam getParam(StructuredQName name)
-
prepareAttributes
public void prepareAttributes()
Description copied from class:StyleElementSet 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:
prepareAttributesin classStyleElement
-
processAllAttributes
public void processAllAttributes() throws XPathExceptionDescription copied from class:StyleElementProcess the attributes of this element and all its children- Overrides:
processAllAttributesin classStyleElement- Throws:
XPathException- in the event of a static error being detected
-
getModeNames
public StructuredQName[] getModeNames() throws XPathException
Return the list of mode names to which this template rule is applicable.- Returns:
- the list of mode names. If the mode attribute is absent, #default is assumed.
If #default is present explicitly or implicitly, it is replaced by the default mode, taken
from the in-scope default-modes attribute, which defaults to #unnamed. The unnamed mode
is represented by
Mode.UNNAMED_MODE_NAME. The token #all translates toMode.OMNI_MODE. - Throws:
XPathException- if the attribute is invalid.
-
getApplicableModes
public java.util.Set<Mode> getApplicableModes() throws XPathException
Get the modes to which this template rule applies- Returns:
- the set of modes to which it applies
- Throws:
XPathException- should not happen
-
isOmniMode
public boolean isOmniMode() throws XPathExceptionAsk whether this is a template rule with mode="#all- Throws:
XPathException
-
validate
public void validate(ComponentDeclaration decl) throws XPathException
Description copied from class:StyleElementCheck 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:
validatein classStyleElement- Parameters:
decl- the declaration to be validated- Throws:
XPathException- if any error is found during validation
-
validateSubtree
public void validateSubtree(ComponentDeclaration decl, boolean excludeStylesheet) throws XPathException
Description copied from class:StyleElementRecursive walk through the stylesheet to validate all nodes- Overrides:
validateSubtreein classStyleElement- Parameters:
decl- the declaration to be validatedexcludeStylesheet- true if the XSLStylesheet element is to be excluded- Throws:
XPathException- if validation fails
-
index
public void index(ComponentDeclaration decl, PrincipalStylesheetModule top) throws XPathException
Description copied from class:StyleElementMethod supplied by declaration elements to add themselves to a stylesheet-level index- Overrides:
indexin classStyleElement- 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- represents the outermost XSLStylesheet or XSLPackage element- Throws:
XPathException- if any error is encountered
-
markTailCalls
public boolean markTailCalls()
Mark tail-recursive calls on templates and functions.- Overrides:
markTailCallsin classStyleElement- Returns:
- true if one or more tail calls were identified
-
compileDeclaration
public void compileDeclaration(Compilation compilation, ComponentDeclaration decl) throws XPathException
Compile: creates the executable form of the template- Overrides:
compileDeclarationin classStyleElement- Parameters:
compilation- the compilation episodedecl- the containing top-level declaration, for example xsl:function or xsl:template- Throws:
XPathException- if compilation fails
-
compileTemplateRule
public void compileTemplateRule(Compilation compilation, Expression body, ComponentDeclaration decl)
-
jitCompile
public void jitCompile(Compilation compilation, ComponentDeclaration decl) throws XPathException
Code executed when the template is first executed under JIT. If the template is defined in several modes, then this may be called several times, but it only does anything the first time. Mode-specific processing is done in the TemplateRuleInitializer.- Parameters:
compilation- the compilation episodedecl- the template rule declaration- Throws:
XPathException- if anything goes wrong
-
register
public void register(ComponentDeclaration 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- if a failure occurs
-
allocatePatternSlotNumbers
public void allocatePatternSlotNumbers()
Allocate slot numbers to any local variables declared within a predicate within the match pattern
-
optimize
public void optimize(ComponentDeclaration 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:
optimizein interfaceStylesheetComponent- 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- if errors are found
-
getContextItemTypeForTemplateRule
public ItemType getContextItemTypeForTemplateRule() throws XPathException
- Throws:
XPathException
-
generateByteCode
public void generateByteCode(Optimizer opt) throws XPathException
Generate byte code for the template (if appropriate)- Specified by:
generateByteCodein interfaceStylesheetComponent- Parameters:
opt- the optimizer- Throws:
XPathException- if byte code generation fails
-
getSlotManager
public SlotManager getSlotManager()
Get associated Procedure (for details of stack frame)- Specified by:
getSlotManagerin interfaceStylesheetComponent- Returns:
- the associated SlotManager object
-
getCompiledNamedTemplate
public NamedTemplate getCompiledNamedTemplate()
Get the compiled template- Returns:
- the compiled template
-
getMatch
public Pattern getMatch()
-
getTemplateRulesByMode
public java.util.Map<StructuredQName,TemplateRule> getTemplateRulesByMode()
-
-