Class PrincipalStylesheetModule

  • All Implemented Interfaces:
    Direct Known Subclasses:

    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
        sourceElement - the xsl:package element at the root of the package manifest
    • Method Detail

      • getComponent

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

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

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

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

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

        public boolean isDeclaredModes()
        Ask whether it is required that modes be explicitly declared
        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
        action - the callback action
      • setNeedsDynamicOutputProperties

        public void setNeedsDynamicOutputProperties​(boolean b)
        Say that this stylesheet package needs dynamic output properties
        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
        the character map index
      • getTypeAliasManager

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

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

        public void putStylesheetDocument​(DocumentKey key,
                                          XSLStylesheet module)
        Add a module to the cache of stylesheet modules
        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
        key - the key to be used (based on the absolute URI)
        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
        XPathException - if errors are found in the stylesheet
      • spliceUsePackages

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

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

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

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

        protected void indexVariableDeclaration​(ComponentDeclaration decl)
                                         throws XPathException
        Index a global xsl:variable or xsl:param element
        decl - The Declaration referencing the XSLVariable or XSLParam element
        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.
        qName - name of the global variable or parameter
        the variable declaration, or null if it does not exist
      • indexNamedTemplate

        protected void indexNamedTemplate​(ComponentDeclaration decl)
                                   throws XPathException
        Add a named template to the index
        decl - the declaration of the Template object
        XPathException - if an error occurs
      • getNamedTemplate

        public NamedTemplate getNamedTemplate​(StructuredQName name)
        Get the named template with a given name
        name - the name of the required template
        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
        decl - the declaration of the attribute set object
        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
        name - the name of the required declarations
        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.
        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).
        aSet - the attribute set to be checked
        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
        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
        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
        template - the template rule
        mode - the mode
      • getAccumulatorManager

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

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

        protected NamespaceBinding getNamespaceAlias​(java.lang.String 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.
        uri - The uri used in the stylesheet.
        The namespace binding to be used (prefix and uri): return null if no alias is defined
      • isAliasResultNamespace

        protected boolean isAliasResultNamespace​(java.lang.String uri)
        Determine if a namespace is included in the result-prefix of a namespace-alias
        uri - the namespace URI
        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.
        formatQName - The name of the output format required. If set to null, gathers information for the unnamed output format
        the Properties object containing the details of the specified output format
        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
        compilation - the compilation episode
        XPathException - if compilation fails for any reason
      • isImportedSchema

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

        protected void addImportedSchema​(java.lang.String targetNamespace)
      • getImportedSchemaTable

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

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

        public void adjustExposedVisibility()
                                     throws XPathException
        Adjust visibility of components by applying xsl:expose rules
      • compileError

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

        protected void compileError​(XPathException error)
        Report an error with diagnostic information
        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
        an existing global variable with the same select expression, if one can be found; otherwise null.