Class PrincipalStylesheetModule

  • All Implemented Interfaces:
    GlobalVariableManager
    Direct Known Subclasses:
    PrincipalStylesheetModuleEE

    public class PrincipalStylesheetModule
    extends StylesheetModule
    implements GlobalVariableManager
    Represents both the stylesheet module at the root of the import tree, that is, the module that includes or imports all the others, and also the XSLT package that has this stylesheet module as its root.

    This version of the StylesheetPackage class represents a trivial package that is constructed by the system to wrap an ordinary (non-package) stylesheet, as available in XSLT 2.0. A subclass is used for "real" packages, currently available only in Saxon-EE.

    • Constructor Detail

      • PrincipalStylesheetModule

        public PrincipalStylesheetModule​(XSLPackage sourceElement)
                                  throws XPathException
        Create a PrincipalStylesheetModule
        Parameters:
        sourceElement - the xsl:package element at the root of the package manifest
        Throws:
        XPathException - if things go wrong
    • Method Detail

      • getComponent

        public Component getComponent​(SymbolicName name)
        Search the package for a component with a given name
        Parameters:
        name - the symbolic name of the required component
        Returns:
        the requested component if found, or null otherwise
      • getStylesheetPackage

        public StylesheetPackage getStylesheetPackage()
        Get the stylesheet package
        Returns:
        the associated stylesheet package
      • getKeyManager

        public KeyManager getKeyManager()
        Get the key manager used to manage xsl:key declarations in this package
        Returns:
        the key manager
      • getDecimalFormatManager

        public DecimalFormatManager getDecimalFormatManager()
        Get the decimal format manager used to manage xsl:decimal-format declarations in this package
        Returns:
        the decimal format manager
      • getRuleManager

        public RuleManager getRuleManager()
        Get the rule manager used to manage modes declared explicitly or implicitly in this package
        Returns:
        the rule manager
      • isDeclaredModes

        public boolean isDeclaredModes()
        Ask whether it is required that modes be explicitly declared
        Returns:
        true if modes referenced within this package must be explicitly declared
      • addFixupAction

        public void addFixupAction​(Action action)
        Register a callback action to be performed during the fixup phase
        Parameters:
        action - the callback action
      • setNeedsDynamicOutputProperties

        public void setNeedsDynamicOutputProperties​(boolean b)
        Say that this stylesheet package needs dynamic output properties
        Parameters:
        b - true if this stylesheet needs dynamic output properties
      • getCharacterMapIndex

        public CharacterMapIndex getCharacterMapIndex()
        Get an index of character maps declared using xsl:character-map entries in this package
        Returns:
        the character map index
      • getTypeAliasManager

        public TypeAliasManager getTypeAliasManager()
        Get the type alias manager (type aliases are a Saxon extension)
        Returns:
        the type alias manager
      • declareXQueryFunction

        public void declareXQueryFunction​(XQueryFunction function)
                                   throws XPathException
        Declare an imported XQuery function
        Parameters:
        function - the imported function
        Throws:
        XPathException - if an error occurs
      • putStylesheetDocument

        public void putStylesheetDocument​(DocumentKey key,
                                          XSLStylesheet module)
        Add a module to the cache of stylesheet modules
        Parameters:
        key - the key to be used (based on the absolute URI)
        module - the stylesheet document tree corresponding to this absolute URI
      • getStylesheetDocument

        public XSLModuleRoot getStylesheetDocument​(DocumentKey key)
        Get a module from the cache of stylesheet modules
        Parameters:
        key - the key to be used (based on the absolute URI)
        Returns:
        the stylesheet document tree corresponding to this absolute URI
      • preprocess

        public void preprocess​(Compilation compilation)
                        throws XPathException
        Preprocess does all the processing possible before the source document is available. It is done once per stylesheet, so the stylesheet can be reused for multiple source documents. The method is called only on the XSLStylesheet element representing the principal stylesheet module
        Parameters:
        compilation - the XSLT compilation in progress
        Throws:
        XPathException - if errors are found in the stylesheet
      • spliceUsePackages

        protected void spliceUsePackages​(XSLPackage xslpackage,
                                         Compilation compilation)
                                  throws XPathException
        Incorporate declarations from used packages
        Parameters:
        xslpackage - the used package
        compilation - this compilation
        Throws:
        XPathException - if any error is detected in the used package
      • importSchemata

        protected void importSchemata()
                               throws XPathException
        Process import-schema declarations
        Throws:
        XPathException - if errors are detected
      • processAllAttributes

        public void processAllAttributes()
        Process the attributes of every node in the stylesheet
        Throws:
        XPathException - if static errors are found in the stylesheet
      • indexFunction

        protected void indexFunction​(ComponentDeclaration decl)
        Add a stylesheet function to the index
        Parameters:
        decl - The declaration wrapping an XSLFunction object
      • indexVariableDeclaration

        protected void indexVariableDeclaration​(ComponentDeclaration decl)
                                         throws XPathException
        Index a global xsl:variable or xsl:param element
        Parameters:
        decl - The Declaration referencing the XSLVariable or XSLParam element
        Throws:
        XPathException - if an error occurs
      • getGlobalVariableBinding

        public SourceBinding getGlobalVariableBinding​(StructuredQName qName)
        Get the global variable or parameter with a given name (taking precedence rules into account). This will only return global variables declared in the same package where they are used.
        Parameters:
        qName - name of the global variable or parameter
        Returns:
        the variable declaration, or null if it does not exist
      • indexNamedTemplate

        protected void indexNamedTemplate​(ComponentDeclaration decl)
        Add a named template to the index
        Parameters:
        decl - the declaration of the Template object
      • getNamedTemplate

        public NamedTemplate getNamedTemplate​(StructuredQName name)
        Get the named template with a given name
        Parameters:
        name - the name of the required template
        Returns:
        the template with the given name, if there is one, or null otherwise. If there are several templates with the same name, the one with highest import precedence is returned. Note that this template may subsequently be overridden in another package, but only by another template with a compatible signature.
      • indexAttributeSet

        protected void indexAttributeSet​(ComponentDeclaration decl)
                                  throws XPathException
        Add an attribute set to the index
        Parameters:
        decl - the declaration of the attribute set object
        Throws:
        XPathException - if an error occurs
      • getAttributeSetDeclarations

        public java.util.List<ComponentDeclaration> getAttributeSetDeclarations​(StructuredQName name)
        Return all the attribute set declarations in the package having a particular QName
        Parameters:
        name - the name of the required declarations
        Returns:
        the set of declarations having this name, or null if there are none
      • combineAttributeSets

        public void combineAttributeSets​(Compilation compilation)
                                  throws XPathException
        Combine all like-named xsl:attribute-set declarations in this package into a single Component, whose body is an AttributeSet object. The resulting attribute set Components are saved in the StylesheetPackage object.
        Parameters:
        compilation - the XSLT compilation in progress
        Throws:
        XPathException - if a failure occurs
      • checkStreamability

        protected void checkStreamability​(AttributeSet aSet)
                                   throws XPathException
        Check the streamability of an attribute set declared within this stylesheet module. (Null implementation for Saxon-HE).
        Parameters:
        aSet - the attribute set to be checked
        Throws:
        XPathException - if the streamability rules are not satisifed
      • getAttributeSets

        protected void getAttributeSets​(StructuredQName name,
                                        java.util.List<ComponentDeclaration> list)
        Get the list of attribute-set declarations associated with a given QName. This is used for xsl:element, xsl:copy, xsl:attribute-set, and on literal result elements
        Parameters:
        name - the name of the required attribute set
        list - a list to hold the list of XSLAttributeSet elements in the stylesheet tree.
      • indexMode

        public void indexMode​(ComponentDeclaration decl)
        Handle an explicitly-declared mode
        Parameters:
        decl - the declaration of the Mode object
      • checkAcceptableModeForPackage

        public boolean checkAcceptableModeForPackage​(XSLTemplate template,
                                                     Mode mode)
        Check that it is legitimate to add a given template rule to a given mode
        Parameters:
        template - the template rule
        mode - the mode
        Returns:
        true if all is well, false if the mode cannot be extended (in which case an error will have been reported)
      • getAccumulatorManager

        public AccumulatorRegistry getAccumulatorManager()
        Get the class that manages accumulator functions
        Returns:
        the class that manages accumulators. Always null in Saxon-HE
      • setAccumulatorManager

        public void setAccumulatorManager​(AccumulatorRegistry accumulatorManager)
        Set the class that manages accumulator functions
        Parameters:
        accumulatorManager - the manager of accumulator functions
      • getNamespaceAlias

        protected NamespaceBinding getNamespaceAlias​(NamespaceUri uri)
        Get the declared namespace alias for a given namespace URI code if there is one. If there is more than one, we get the last.
        Parameters:
        uri - The uri used in the stylesheet.
        Returns:
        The namespace binding to be used (prefix and uri): return null if no alias is defined
      • isAliasResultNamespace

        protected boolean isAliasResultNamespace​(NamespaceUri uri)
        Determine if a namespace is included in the result-prefix of a namespace-alias
        Parameters:
        uri - the namespace URI
        Returns:
        true if an xsl:namespace-alias has been defined for this namespace URI
      • hasNamespaceAliases

        protected boolean hasNamespaceAliases()
      • gatherOutputProperties

        public java.util.Properties gatherOutputProperties​(StructuredQName formatQName)
                                                    throws XPathException
        Create an output properties object representing the xsl:output elements in the stylesheet.
        Parameters:
        formatQName - The name of the output format required. If set to null, gathers information for the unnamed output format
        Returns:
        the Properties object containing the details of the specified output format
        Throws:
        XPathException - if a named output format does not exist in the stylesheet
      • compile

        protected void compile​(Compilation compilation)
                        throws XPathException
        Compile the source XSLT stylesheet package
        Parameters:
        compilation - the compilation episode
        Throws:
        XPathException - if compilation fails for any reason
      • isImportedSchema

        protected boolean isImportedSchema​(NamespaceUri targetNamespace)
        Get an imported schema with a given namespace
        Parameters:
        targetNamespace - The target namespace of the required schema. Supply an empty string for the default namespace
        Returns:
        the required Schema, or null if no such schema has been imported
      • addImportedSchema

        protected void addImportedSchema​(NamespaceUri targetNamespace)
      • getImportedSchemaTable

        protected java.util.Set<NamespaceUri> getImportedSchemaTable()
      • getCharacterMap

        public ComponentDeclaration getCharacterMap​(StructuredQName name)
        Get a character map, identified by the fingerprint of its name. Search backwards through the stylesheet.
        Parameters:
        name - The character map name being sought
        Returns:
        the identified character map, or null if not found
      • adjustExposedVisibility

        public void adjustExposedVisibility()
                                     throws XPathException
        Adjust visibility of components by applying xsl:expose rules
        Throws:
        XPathException - if this detects an error or inconsistency
      • compileError

        protected void compileError​(java.lang.String message,
                                    java.lang.String errorCode)
                             throws XPathException
        Compile time error, specifying an error code
        Parameters:
        message - the error message
        errorCode - the error code. May be null if not known or not defined
        Throws:
        XPathException - unconditionally
      • compileError

        protected void compileError​(XPathException error)
        Report an error with diagnostic information
        Parameters:
        error - contains information about the error
      • getEquivalentVariable

        public GlobalVariable getEquivalentVariable​(Expression select)
        Description copied from interface: GlobalVariableManager
        Get an existing global variable whose initializer is a given expression, if there is one. Note that this depends on the logic for detecting equivalence of expressions, which is necessarily approximate. Expressions with dependencies on the static context should never be considered equivalent. If no equivalent global variable is found, return null. An implementation can always return null if it wants to avoid a lengthy search.
        Specified by:
        getEquivalentVariable in interface GlobalVariableManager
        Parameters:
        select - the expression to which the variable is bound
        Returns:
        an existing global variable with the same select expression, if one can be found; otherwise null.