Package net.sf.saxon.style
Class ExpressionContext
- java.lang.Object
-
- net.sf.saxon.style.ExpressionContext
-
- All Implemented Interfaces:
StaticContext
,XSLTStaticContext
public class ExpressionContext extends java.lang.Object implements XSLTStaticContext
An ExpressionContext represents the context for an XPath expression written in the stylesheet.
-
-
Constructor Summary
Constructors Constructor Description ExpressionContext(StyleElement styleElement)
Create a static context for XPath expressions in an XSLT stylesheet
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Expression
bindVariable(StructuredQName qName)
Bind a variable to an object that can be used to refer to itjava.lang.String
getBaseURI()
Get the Base URI of the element containing the expression, for resolving any relative URI's used in the expression.StringCollator
getCollation(java.lang.String name)
Get a named collation.Configuration
getConfiguration()
Get the system configurationDecimalFormatManager
getDecimalFormatManager()
Get a DecimalFormatManager to resolve the names of decimal formats used in calls to the format-number() function.java.lang.String
getDefaultCollationName()
Get the default collation.java.lang.String
getDefaultElementNamespace()
Get the default XPath namespace for elements and types Return NamespaceConstant.NULL for the non-namespacejava.lang.String
getDefaultFunctionNamespace()
Get the default function namespaceExecutable
getExecutable()
Get the executableint
getFingerprint(java.lang.String qname, boolean useDefault)
Get a fingerprint for a name, using this as the context for namespace resolutionFunctionLibrary
getFunctionLibrary()
Get the function library containing all the in-scope functions available in this static contextjava.util.Set<java.lang.String>
getImportedSchemaNamespaces()
Get the set of imported schemasint
getLineNumber()
Get the line number of the expression within its containing entity Returns -1 if no line number is availableLocationMap
getLocationMap()
Get the location mapNamePool
getNamePool()
Get the NamePool used for compiling expressionsNamespaceResolver
getNamespaceResolver()
Get a copy of the NamespaceResolver suitable for saving in the executable codeItemType
getRequiredContextItemType()
Get the required type of the context item.StructuredQName
getStructuredQName(java.lang.String qname, boolean useDefault)
Get a StructuredQName for a name, using this as the context for namespace resolutionStyleElement
getStyleElement()
Get the stylesheet element containing this XPath expressionjava.lang.String
getSystemId()
Get the System ID of the entity containing the expression (used for diagnostics)java.lang.String
getURIForPrefix(java.lang.String prefix)
Get the URI for a prefix, using this Element as the context for namespace resolution.DecimalValue
getXPathLanguageLevel()
Get the XPath language level supported, as a string.boolean
isAllowedBuiltInType(BuiltInAtomicType type)
Determine whether a built-in type is available in this context.boolean
isElementAvailable(java.lang.String qname)
Determine if an extension element is availableboolean
isImportedSchema(java.lang.String namespace)
Test whether a schema has been imported for a given namespaceboolean
isInBackwardsCompatibleMode()
Determine whether Backwards Compatible Mode is usedboolean
isSchemaAware()
Ask whether expressions compiled under this static context are schema-aware.void
issueWarning(java.lang.String s, javax.xml.transform.SourceLocator locator)
Issue a compile-time warningXPathContext
makeEarlyEvaluationContext()
Construct a dynamic context for early evaluation of constant subexpressions
-
-
-
Constructor Detail
-
ExpressionContext
public ExpressionContext(StyleElement styleElement)
Create a static context for XPath expressions in an XSLT stylesheet- Parameters:
styleElement
- the element on which the XPath expression appears
-
-
Method Detail
-
getConfiguration
public Configuration getConfiguration()
Get the system configuration- Specified by:
getConfiguration
in interfaceStaticContext
- Returns:
- the Saxon configuration
-
getExecutable
public Executable getExecutable()
Get the executable- Returns:
- the executable
-
isSchemaAware
public boolean isSchemaAware()
Ask whether expressions compiled under this static context are schema-aware. They must be schema-aware if the expression is to handle typed (validated) nodes- Specified by:
isSchemaAware
in interfaceStaticContext
- Returns:
- true if expressions are schema-aware
-
makeEarlyEvaluationContext
public XPathContext makeEarlyEvaluationContext()
Construct a dynamic context for early evaluation of constant subexpressions- Specified by:
makeEarlyEvaluationContext
in interfaceStaticContext
- Returns:
- a newly constructed dynamic context
-
getLocationMap
public LocationMap getLocationMap()
Get the location map- Specified by:
getLocationMap
in interfaceStaticContext
- Returns:
- the location map
-
issueWarning
public void issueWarning(java.lang.String s, javax.xml.transform.SourceLocator locator)
Issue a compile-time warning- Specified by:
issueWarning
in interfaceStaticContext
- Parameters:
s
- The warning message. This should not contain any prefix such as "Warning".locator
- the location of the construct in question. May be null.
-
getNamePool
public NamePool getNamePool()
Get the NamePool used for compiling expressions- Specified by:
getNamePool
in interfaceStaticContext
- Returns:
- the name pool
-
getSystemId
public java.lang.String getSystemId()
Get the System ID of the entity containing the expression (used for diagnostics)- Specified by:
getSystemId
in interfaceStaticContext
- Returns:
- the system ID
-
getLineNumber
public int getLineNumber()
Get the line number of the expression within its containing entity Returns -1 if no line number is available- Specified by:
getLineNumber
in interfaceStaticContext
- Returns:
- the line number, or -1 if not available
-
getBaseURI
public java.lang.String getBaseURI()
Get the Base URI of the element containing the expression, for resolving any relative URI's used in the expression. Used by the document() function.- Specified by:
getBaseURI
in interfaceStaticContext
- Returns:
- the static base URI, or null if not known
-
getURIForPrefix
public java.lang.String getURIForPrefix(java.lang.String prefix) throws XPathException
Get the URI for a prefix, using this Element as the context for namespace resolution. The default namespace will not be used when the prefix is empty.- Specified by:
getURIForPrefix
in interfaceStaticContext
- Parameters:
prefix
- The prefix- Returns:
- the corresponding namespace URI
- Throws:
XPathException
- if the prefix is not declared
-
getNamespaceResolver
public NamespaceResolver getNamespaceResolver()
Get a copy of the NamespaceResolver suitable for saving in the executable code- Specified by:
getNamespaceResolver
in interfaceStaticContext
- Returns:
- a NamespaceResolver
-
getRequiredContextItemType
public ItemType getRequiredContextItemType()
Get the required type of the context item. If no type has been explicitly declared for the context item, an instance of AnyItemType (representing the type item()) is returned.- Specified by:
getRequiredContextItemType
in interfaceStaticContext
- Returns:
- the required type of the context item
- Since:
- 9.3
-
getDecimalFormatManager
public DecimalFormatManager getDecimalFormatManager()
Get a DecimalFormatManager to resolve the names of decimal formats used in calls to the format-number() function.- Specified by:
getDecimalFormatManager
in interfaceStaticContext
- Returns:
- the decimal format manager for this static context, or null if named decimal formats are not supported in this environment.
-
getFingerprint
public int getFingerprint(java.lang.String qname, boolean useDefault) throws XPathException
Get a fingerprint for a name, using this as the context for namespace resolution- Parameters:
qname
- The name as written, in the form "[prefix:]localname"useDefault
- Defines the action when there is no prefix. If true, use the default namespace URI (as for element names). If false, use no namespace URI (as for attribute names).- Returns:
- -1 if the name is not already present in the name pool
- Throws:
XPathException
-
getStructuredQName
public StructuredQName getStructuredQName(java.lang.String qname, boolean useDefault) throws XPathException
Get a StructuredQName for a name, using this as the context for namespace resolution- Parameters:
qname
- The name as written, in the form "[prefix:]localname"useDefault
- Defines the action when there is no prefix. If true, use the default namespace URI (as for element names). If false, use no namespace URI (as for attribute names).- Returns:
- -1 if the name is not already present in the name pool
- Throws:
XPathException
-
bindVariable
public Expression bindVariable(StructuredQName qName) throws XPathException
Bind a variable to an object that can be used to refer to it- Specified by:
bindVariable
in interfaceStaticContext
- Parameters:
qName
- the name of the variable- Returns:
- a VariableDeclaration object that can be used to identify it in the Bindery,
- Throws:
XPathException
- if the variable has not been declared
-
getFunctionLibrary
public FunctionLibrary getFunctionLibrary()
Get the function library containing all the in-scope functions available in this static context- Specified by:
getFunctionLibrary
in interfaceStaticContext
- Returns:
- the function library
-
isElementAvailable
public boolean isElementAvailable(java.lang.String qname) throws XPathException
Determine if an extension element is available- Specified by:
isElementAvailable
in interfaceXSLTStaticContext
- Throws:
XPathException
- if the name is invalid or the prefix is not declared
-
getCollation
public StringCollator getCollation(java.lang.String name)
Get a named collation.- Specified by:
getCollation
in interfaceStaticContext
- Parameters:
name
- The name of the required collation. Supply null to get the default collation.- Returns:
- the collation; or null if the required collation is not found.
-
getDefaultCollationName
public java.lang.String getDefaultCollationName()
Get the default collation. Return null if no default collation has been defined- Specified by:
getDefaultCollationName
in interfaceStaticContext
- Returns:
- the name of the default collation; or the name of the codepoint collation if no default collation has been defined
-
getDefaultElementNamespace
public java.lang.String getDefaultElementNamespace()
Get the default XPath namespace for elements and types Return NamespaceConstant.NULL for the non-namespace- Specified by:
getDefaultElementNamespace
in interfaceStaticContext
- Returns:
- the default namespace, or NamespaceConstant.NULL for the non-namespace
-
getDefaultFunctionNamespace
public java.lang.String getDefaultFunctionNamespace()
Get the default function namespace- Specified by:
getDefaultFunctionNamespace
in interfaceStaticContext
- Returns:
- the default namespace for function names
-
isInBackwardsCompatibleMode
public boolean isInBackwardsCompatibleMode()
Determine whether Backwards Compatible Mode is used- Specified by:
isInBackwardsCompatibleMode
in interfaceStaticContext
- Returns:
- true if 1.0 compaibility mode is in force.
-
getXPathLanguageLevel
public DecimalValue getXPathLanguageLevel()
Get the XPath language level supported, as a string. The current levels supported are 2.0, and 3.0. The XPath language level will be the same as the XSLT processor version- Specified by:
getXPathLanguageLevel
in interfaceStaticContext
- Returns:
- the XPath language level; the return value will be either
DecimalValue.TWO
orDecimalValue.THREE
- Since:
- 9.3
-
isImportedSchema
public boolean isImportedSchema(java.lang.String namespace)
Test whether a schema has been imported for a given namespace- Specified by:
isImportedSchema
in interfaceStaticContext
- Parameters:
namespace
- the target namespace of the required schema- Returns:
- true if a schema for this namespace has been imported
-
getImportedSchemaNamespaces
public java.util.Set<java.lang.String> getImportedSchemaNamespaces()
Get the set of imported schemas- Specified by:
getImportedSchemaNamespaces
in interfaceStaticContext
- Returns:
- a Set, the set of URIs representing the names of imported schemas
-
isAllowedBuiltInType
public boolean isAllowedBuiltInType(BuiltInAtomicType type)
Determine whether a built-in type is available in this context. This method caters for differences between host languages as to which set of types are built in.- Specified by:
isAllowedBuiltInType
in interfaceStaticContext
- Parameters:
type
- the supposedly built-in type. This will always be a type in the XS or XDT namespace.- Returns:
- true if this type can be used in this static context
-
getStyleElement
public StyleElement getStyleElement()
Get the stylesheet element containing this XPath expression- Returns:
- the element in the tree representation of the source stylesheet
-
-