A Pattern represents the result of parsing an XSLT pattern string.
Patterns are created by calling the static method Pattern.make(string).
The pattern is used to test a particular node by calling match().
allocateSlots
public int allocateSlots(ExpressionContext env,
int nextFree)
Allocate slots to any variables used within the pattern
env
- the static context in the XSLT stylesheetnextFree
- the next slot that is free to be allocated
- the next slot that is free to be allocated
analyze
public Pattern analyze(ExpressionVisitor visitor,
ItemType contextItemType)
throws XPathException
Type-check the pattern.
Default implementation does nothing. This is only needed for patterns that contain
variable references or function calls.
visitor
- the expression visitorcontextItemType
- the type of the context item, if known, at the point where the pattern
is defined
getColumnNumber
public int getColumnNumber()
Get the column number (always -1)
getDefaultPriority
public double getDefaultPriority()
Determine the default priority to use if this pattern appears as a match pattern
for a template with no explicit priority attribute.
- the default priority for the pattern
getDependencies
public int getDependencies()
Get the dependencies of the pattern. The only possible dependency for a pattern is
on local variables. This is analyzed in those patterns where local variables may appear.
- the dependencies, as a bit-significant mask
getFingerprint
public int getFingerprint()
Determine the name fingerprint of nodes to which this pattern applies. Used for
optimisation.
- A fingerprint that the nodes must match, or -1 if it can match multiple fingerprints
getHostLanguage
public int getHostLanguage()
Get the host language (XSLT, XQuery, XPath) used to implement the code in this container
- getHostLanguage in interface Container
getLineNumber
public int getLineNumber()
Get the line number on which the pattern was defined
getNodeKind
public int getNodeKind()
Determine the types of nodes to which this pattern applies. Used for optimisation.
For patterns that match nodes of several types, return Type.NODE
- the type of node matched by this pattern. e.g. Type.ELEMENT or Type.TEXT
getNodeTest
public abstract NodeTest getNodeTest()
Get a NodeTest that all the nodes matching this pattern must satisfy
- a NodeTest, as specific as possible, which all the matching nodes satisfy
getPublicId
public String getPublicId()
Get the public ID (always null)
getSystemId
public String getSystemId()
Get the system id of the entity in which the pattern occurred
internalMatches
protected boolean internalMatches(NodeInfo node,
XPathContext context)
throws XPathException
Determine whether this Pattern matches the given Node. This is an internal interface used
for matching sub-patterns; it does not alter the value of current(). The default implementation
is identical to matches().
node
- The NodeInfo representing the Element or other node to be tested against the Patterncontext
- The dynamic context. Only relevant if the pattern
uses variables, or contains calls on functions such as document() or key().
- true if the node matches the Pattern, false otherwise
iterateSubExpressions
public Iterator iterateSubExpressions()
Iterate over the subexpressions within this pattern
- an iterator over the subexpressions. Default implementation returns an empty sequence
make
public static Pattern make(String pattern,
StaticContext env,
Executable exec)
throws XPathException
Static method to make a Pattern by parsing a String.
pattern
- The pattern text as a Stringenv
- An object defining the compile-time context for the expressionexec
- The executable containing this pattern
makeSearchExpression
public Expression makeSearchExpression()
Make an expression whose effect is to select all the nodes that match this pattern
in a given document. This expression takes the root of the tree (always a document node)
as the context node; it takes into account all the constraints expressed by the pattern
including the parent and ancestor nodes and the filters
matches
public abstract boolean matches(NodeInfo node,
XPathContext context)
throws XPathException
Determine whether this Pattern matches the given Node. This is the main external interface
for matching patterns: it sets current() to the node being tested
node
- The NodeInfo representing the Element or other node to be tested against the Patterncontext
- The dynamic context. Only relevant if the pattern
uses variables, or contains calls on functions such as document() or key().
- true if the node matches the Pattern, false otherwise
promote
public void promote(PromotionOffer offer)
throws XPathException
Offer promotion for subexpressions within this pattern. The offer will be accepted if the subexpression
is not dependent on the factors (e.g. the context item) identified in the PromotionOffer.
By default the offer is not accepted - this is appropriate in the case of simple expressions
such as constant values and variable references where promotion would give no performance
advantage. This method is always called at compile time.
Unlike the corresponding method on
Expression
, this method does not return anything:
it can make internal changes to the pattern, but cannot return a different pattern. Only certain
kinds of promotion are applicable within a pattern: specifically, promotions affecting local
variable references within the pattern.
offer
- details of the offer, for example the offer to move
expressions that don't depend on the context to an outer level in
the containing expression
setExecutable
public void setExecutable(Executable executable)
Set the executable containing this pattern
executable
- the executable
setLineNumber
public void setLineNumber(int lineNumber)
Set the line number where the pattern occurred
lineNumber
- the line number of the pattern in the source module
setOriginalText
public void setOriginalText(String text)
Set the original text of the pattern for use in diagnostics
text
- the original text of the pattern
setSystemId
public void setSystemId(String systemId)
Set the system ID where the pattern occurred
systemId
- the URI of the module containing the pattern
simplify
public Pattern simplify(ExpressionVisitor visitor)
throws XPathException
Simplify the pattern by applying any context-independent optimisations.
Default implementation does nothing.
visitor
- the expression visitor
toString
public String toString()
Get the original pattern text