net.sf.saxon.sxpath
Class IndependentContext
- Container, Serializable, SourceLocator, Container, NamespaceResolver, SourceLocator, StaticContext, XPathStaticContext
public class IndependentContext
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.
VariableReference | bindVariable(StructuredQName qName) - Bind a variable used in an XPath Expression to the XSLVariable element in which it is declared.
|
void | clearAllNamespaces() - Clear all the declared namespaces, including the standard ones (xml, xslt, saxon).
|
void | clearNamespaces() - Clear all the declared namespaces, except for the standard ones (xml, xslt, saxon, xdt).
|
IndependentContext | copy() - Create a copy of this IndependentContext.
|
void | declareNamespace(String prefix, String uri) - Declare a namespace whose prefix can be used in expressions
|
XPathVariable | declareVariable(String namespaceURI, String localName) - Declare a variable.
|
XPathVariable | declareVariable(QNameValue qname) - Declare a variable.
|
Set | getImportedSchemaNamespaces() - Get the set of imported schemas
|
NamespaceResolver | getNamespaceResolver()
|
int | getSlotNumber(QNameValue qname) - Get the slot number allocated to a particular variable
|
SlotManager | getStackFrameMap() - Get a Stack Frame Map containing definitions of all the declared variables.
|
String | getURIForPrefix(String prefix) - Get the URI for a prefix, using the declared namespaces as
the context for namespace resolution.
|
String | getURIForPrefix(String prefix, boolean useDefault) - Get the namespace URI corresponding to a given prefix.
|
boolean | isImportedSchema(String namespace)
|
Iterator | iteratePrefixes() - Get an iterator over all the prefixes declared in this namespace context.
|
void | setImportedSchemaNamespaces(Set namespaces) - Register the set of imported schema namespaces
|
void | setNamespaceResolver(NamespaceResolver resolver) - Set an external namespace resolver.
|
void | setNamespaces(NodeInfo node) - Declares all the namespaces that are in-scope for a given node, removing all previous
namespace declarations.
|
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 , setLocationMap |
IndependentContext
public IndependentContext()
Create an IndependentContext along with a new (non-schema-aware) Saxon Configuration
IndependentContext
public IndependentContext(Configuration config)
Create an IndependentContext using a specific Configuration
config
- the Saxon configuration to be used
bindVariable
public VariableReference bindVariable(StructuredQName qName)
throws XPathException
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.
- bindVariable in interface StaticContext
qName
- the name of the variable
- the resulting variable reference
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.
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
copy
public IndependentContext copy()
Create a copy of this IndependentContext. All aspects of the context are copied
except for declared variables.
declareNamespace
public void declareNamespace(String prefix,
String uri)
Declare a namespace whose prefix can be used in expressions
prefix
- The namespace prefix. Must not be null. Supplying "" sets the
default element namespace.uri
- The namespace URI. Must not be null.
declareVariable
public XPathVariable declareVariable(String namespaceURI,
String localName)
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
- declareVariable in interface XPathStaticContext
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)
- an XPathVariable object representing information about the variable that has been
declared.
declareVariable
public XPathVariable declareVariable(QNameValue qname)
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
- declareVariable in interface XPathStaticContext
qname
- The name of the variable
- an XPathVariable object representing information about the variable that has been
declared.
getImportedSchemaNamespaces
public Set getImportedSchemaNamespaces()
Get the set of imported schemas
- getImportedSchemaNamespaces in interface StaticContext
- a Set, the set of URIs representing the names of imported schemas
getSlotNumber
public int getSlotNumber(QNameValue qname)
Get the slot number allocated to a particular variable
qname
- the name of the variable
- the slot number, or -1 if the variable has not been declared
getStackFrameMap
public SlotManager 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.
- getStackFrameMap in interface XPathStaticContext
getURIForPrefix
public String getURIForPrefix(String prefix)
throws XPathException
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.
- getURIForPrefix in interface StaticContext
getURIForPrefix
public String getURIForPrefix(String prefix,
boolean useDefault)
Get the namespace URI corresponding to a given prefix. Return null
if the prefix is not in scope.
- getURIForPrefix in interface NamespaceResolver
prefix
- the namespace prefixuseDefault
- true if the default namespace is to be used when the
prefix is ""
- the uri for the namespace, or null if the prefix is not in scope.
Return "" if the prefix maps to the null namespace.
iteratePrefixes
public Iterator 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
- iteratePrefixes in interface NamespaceResolver
setImportedSchemaNamespaces
public void setImportedSchemaNamespaces(Set namespaces)
Register the set of imported schema namespaces
namespaces
- the set of namespaces for which schema components are available in the
static context
setNamespaceResolver
public void setNamespaceResolver(NamespaceResolver resolver)
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.
- setNamespaceResolver in interface XPathStaticContext
resolver
- the external NamespaceResolver
setNamespaces
public void setNamespaces(NodeInfo node)
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.
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.