Package net.sf.saxon.sxpath
Class IndependentContext
java.lang.Object
net.sf.saxon.sxpath.AbstractStaticContext
net.sf.saxon.sxpath.IndependentContext
- All Implemented Interfaces:
Serializable,SourceLocator,Container,StaticContext,NamespaceResolver,XPathStaticContext
public class IndependentContext
extends AbstractStaticContext
implements XPathStaticContext, NamespaceResolver, Serializable, Container
An IndependentContext provides a context for parsing an XPath expression appearing
in a context other than a stylesheet.
This class is used in a number of places where freestanding XPath expressions occur. These include the native Saxon XPath API, the .NET XPath API, XPath expressions used in XML Schema identity constraints, and XPath expressions supplied to saxon:evaluate(). It is not used by the JAXP XPath API (though it shares code with that API through the common superclass AbstractStaticContext).
This class currently provides no mechanism for binding user-defined functions.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an IndependentContext along with a new (non-schema-aware) Saxon ConfigurationIndependentContext(Configuration config) Create an IndependentContext using a specific Configuration -
Method Summary
Modifier and TypeMethodDescriptionbindVariable(StructuredQName qName) Bind a variable used in an XPath Expression to the XSLVariable element in which it is declared.voidClear all the declared namespaces, including the standard ones (xml, xslt, saxon).voidClear all the declared namespaces, except for the standard ones (xml, xslt, saxon, xdt).copy()Create a copy of this IndependentContext.voiddeclareNamespace(String prefix, String uri) Declare a namespace whose prefix can be used in expressionsdeclareVariable(String namespaceURI, String localName) Declare a variable.declareVariable(QNameValue qname) Declare a variable.Get the set of imported schemasGet a namespace resolver to resolve the namespaces declared in this static context.intgetSlotNumber(QNameValue qname) Get the slot number allocated to a particular variableGet a Stack Frame Map containing definitions of all the declared variables.getURIForPrefix(String prefix) Get the URI for a prefix, using the declared namespaces as the context for namespace resolution.getURIForPrefix(String prefix, boolean useDefault) Get the namespace URI corresponding to a given prefix.booleanisImportedSchema(String namespace) Determine whether a Schema for a given target namespace has been imported.Get an iterator over all the prefixes declared in this namespace context.voidsetImportedSchemaNamespaces(Set namespaces) Register the set of imported schema namespacesvoidsetNamespaceResolver(NamespaceResolver resolver) Set an external namespace resolver.voidsetNamespaces(NodeInfo node) Declares all the namespaces that are in-scope for a given node, removing all previous namespace declarations.Methods inherited from class net.sf.saxon.sxpath.AbstractStaticContext
addFunctionLibrary, declareCollation, getBaseURI, getCollation, getColumnNumber, getConfiguration, getDefaultCollationName, getDefaultElementNamespace, getDefaultFunctionNamespace, getExecutable, getFunctionLibrary, getHostLanguage, getLineNumber, getLocationMap, getLocationProvider, getNamePool, getPublicId, getSystemId, isAllowedBuiltInType, isInBackwardsCompatibleMode, issueWarning, makeEarlyEvaluationContext, replaceSubExpression, setBackwardsCompatibilityMode, setBaseURI, setConfiguration, setDefaultElementNamespace, setDefaultFunctionLibrary, setDefaultFunctionNamespace, setFunctionLibrary, setLocationMapMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.sf.saxon.expr.Container
getHostLanguage, getLocationProvider, replaceSubExpressionMethods inherited from interface javax.xml.transform.SourceLocator
getColumnNumber, getLineNumber, getPublicId, getSystemIdMethods inherited from interface net.sf.saxon.expr.StaticContext
getBaseURI, getCollation, getConfiguration, getDefaultCollationName, getDefaultElementNamespace, getDefaultFunctionNamespace, getFunctionLibrary, getLineNumber, getLocationMap, getNamePool, getSystemId, isAllowedBuiltInType, isInBackwardsCompatibleMode, issueWarning, makeEarlyEvaluationContextMethods inherited from interface net.sf.saxon.sxpath.XPathStaticContext
getExecutable, setDefaultElementNamespace
-
Constructor Details
-
IndependentContext
public IndependentContext()Create an IndependentContext along with a new (non-schema-aware) Saxon Configuration -
IndependentContext
Create an IndependentContext using a specific Configuration- Parameters:
config- the Saxon configuration to be used
-
-
Method Details
-
copy
Create a copy of this IndependentContext. All aspects of the context are copied except for declared variables.- Returns:
- the new copy
-
declareNamespace
Declare a namespace whose prefix can be used in expressions- Parameters:
prefix- The namespace prefix. Must not be null. Supplying "" sets the default element namespace.uri- The namespace URI. Must not be null.
-
clearNamespaces
public void clearNamespaces()Clear all the declared namespaces, except for the standard ones (xml, xslt, saxon, xdt). This also resets the default element namespace to the "null" namespace -
clearAllNamespaces
public void clearAllNamespaces()Clear all the declared namespaces, including the standard ones (xml, xslt, saxon). Leave only the XML namespace and the default namespace (xmlns=""). This also resets the default element namespace to the "null" namespace. -
setNamespaces
Declares all the namespaces that are in-scope for a given node, removing all previous namespace declarations. In addition, the standard namespaces (xml, xslt, saxon) are declared. This method also sets the default element namespace to be the same as the default namespace for this node.- Parameters:
node- The node whose in-scope namespaces are to be used as the context namespaces. If the node is an attribute, text node, etc, then the namespaces of its parent element are used.
-
setNamespaceResolver
Set an external namespace resolver. If this is set, then all resolution of namespace prefixes is delegated to the external namespace resolver, and namespaces declared individually on this IndependentContext object are ignored.- Specified by:
setNamespaceResolverin interfaceXPathStaticContext- Parameters:
resolver- the external NamespaceResolver
-
declareVariable
Declare a variable. A variable must be declared before an expression referring to it is compiled. The initial value of the variable will be the empty sequence- Specified by:
declareVariablein interfaceXPathStaticContext- Parameters:
qname- The name of the variable- Returns:
- an XPathVariable object representing information about the variable that has been declared.
-
declareVariable
Declare a variable. A variable must be declared before an expression referring to it is compiled. The initial value of the variable will be the empty sequence- Specified by:
declareVariablein interfaceXPathStaticContext- Parameters:
namespaceURI- The namespace URI of the name of the variable. Supply "" to represent names in no namespace (null is also accepted)localName- The local part of the name of the variable (an NCName)- Returns:
- an XPathVariable object representing information about the variable that has been declared.
-
getSlotNumber
Get the slot number allocated to a particular variable- Parameters:
qname- the name of the variable- Returns:
- the slot number, or -1 if the variable has not been declared
-
getURIForPrefix
Get the URI for a prefix, using the declared namespaces as the context for namespace resolution. The default namespace is NOT used when the prefix is empty. This method is provided for use by the XPath parser.- Specified by:
getURIForPrefixin interfaceStaticContext- Parameters:
prefix- The prefix- Returns:
- the corresponding namespace URI
- Throws:
XPathException- if the prefix is not declared
-
getNamespaceResolver
Description copied from interface:StaticContextGet a namespace resolver to resolve the namespaces declared in this static context.- Specified by:
getNamespaceResolverin interfaceStaticContext- Returns:
- a namespace resolver.
-
getURIForPrefix
Get the namespace URI corresponding to a given prefix. Return null if the prefix is not in scope.- Specified by:
getURIForPrefixin interfaceNamespaceResolver- Parameters:
prefix- the namespace prefixuseDefault- true if the default namespace is to be used when the prefix is ""- Returns:
- the uri for the namespace, or null if the prefix is not in scope. Return "" if the prefix maps to the null namespace.
-
iteratePrefixes
Get an iterator over all the prefixes declared in this namespace context. This will include the default namespace (prefix="") and the XML namespace where appropriate- Specified by:
iteratePrefixesin interfaceNamespaceResolver
-
bindVariable
Bind a variable used in an XPath Expression to the XSLVariable element in which it is declared. This method is provided for use by the XPath parser, and it should not be called by the user of the API, or overridden, unless variables are to be declared using a mechanism other than the declareVariable method of this class.- Specified by:
bindVariablein interfaceStaticContext- Parameters:
qName- the name of the variable- Returns:
- the resulting variable reference
- Throws:
XPathException
-
getStackFrameMap
Get a Stack Frame Map containing definitions of all the declared variables. This will return a newly created object that the caller is free to modify by adding additional variables, without affecting the static context itself.- Specified by:
getStackFrameMapin interfaceXPathStaticContext- Returns:
- a SlotManager object holding details of the allocation of variables on the stack frame.
-
isImportedSchema
Description copied from interface:StaticContextDetermine whether a Schema for a given target namespace has been imported. Note that the in-scope element declarations, attribute declarations and schema types are the types registered with the (schema-aware) configuration, provided that their namespace URI is registered in the static context as being an imported schema namespace. (A consequence of this is that within a Configuration, there can only be one schema for any given namespace, including the null namespace).- Specified by:
isImportedSchemain interfaceStaticContext- Parameters:
namespace- the target namespace in question- Returns:
- true if the given namespace has been imported
-
getImportedSchemaNamespaces
Get the set of imported schemas- Specified by:
getImportedSchemaNamespacesin interfaceStaticContext- Returns:
- a Set, the set of URIs representing the names of imported schemas
-
setImportedSchemaNamespaces
Register the set of imported schema namespaces- Parameters:
namespaces- the set of namespaces for which schema components are available in the static context
-