Class Def2Xslt3


public class Def2Xslt3 extends Navigate.VisitReachable<Object>
Collects XSLT rules (and the necessary namespace declarations) in d2d format from a set of resolved modules, for one particular transformation target key. All collected rules are written as one single text to a writer. These rules are (a) at most one rule for each reachable raw (=unresolved) definition, and (b) the module-level "library" rules for all touched raw modules and all their containing modules.

Every rule for a definition is tranformed into a "<xslt:template match="XMLTAG"> output fragment. The library code for all reached modules is copied verbatim.

The xslt rules are defined with the "raw" definitions, thus they are the same for their different parametrizations.

Usage is one-shot:
FIXME SHIFT PARAMETERS TO CONSTRUCTOR !?!?
Construct an instance of this class (always anew, no re-usage) and then call extract(String,String,Strin,XMLDocumentIdentifier,LocationMap, String, PrintWriter, ResolvedModule...).

When parsing any d2d-encoded xslt source, namespace declarations. i.e. mappings from prefix to nsUri, are

  • The element structure of the d2d-encoded xslt source is parsed from d2d-tags, which are (possibly context sensitive) wordings, not including any namespace information. These yield elements, which in turn may have a namspaceUri in their xml encoding. This holds for both xslt elements and target elements. It holds for target formats given by a ddf or by a dtd (in that case the Dtd2ddf collects the namespace declarations by the tdom-pi, resolves the prefices into nsUris of the generated Definition and strips them for use as tags.) The target model definition must be addressable by the normal d2d module finding. The d2d xslt source identifies the top-level target model in its headline "d2d xslt producing XY".
  • In case of explicitly written, stand alone xslt files, the input xml model is present only in "match" patterns of templates, and in all xpath expressions in attributes of xslt elements and in attribute templates of some xslt elements and all result elements. The namespaces of the input model can NOT be derived from the d2d-data, and the prefix-nsUri-relation must be THE SAME as written/meant in the source text in the contained xpath expressions. Since these are not analysed here, and thus no re-mapping of the prefices is possible, this relation must (a) be declared manually, by a "from"-declaration, must (b) be taken over to the resulting xslt model verbatim, and (c) must not conflict with any other declaration of this kind.
  • In case of an xslt source *extracted* from a "docu_to[]" entry in the d2d Module, the input model namespace uris are known, and the prefix COULD be re-mapped for the automatically generated top-level "xsl.template match='...'" attributes. BUT this does not hold for other xpath expressions written explicitly by the user in xslt attributes or result attribute templates, as described for the preceding case.
  • The same holds for third-party documents, inquired explicitly, eg. by the xpath function "document(...)", with different nsUris internally.
  • The declarations of the input document in this "extracted" case are contained completely in the currently processed d2d module and all its imported modules. For these, "from" namespace declarations are added automatically, by this code.

    The declaration of the target model is completely defined when resolving the key part of the "docu_to_[key]" into a d2d Module and will be identified by the headline of the generated xslt source text.

  • All third-party namespace mappings must be defined explicitly in the former! HOW ???? FIXME
The "meta" module will be extracted to the same target format, iff it is provided as an parameter.
  • Field Details

    • defaultXsltLib

      @Opt protected @Opt String defaultXsltLib
      Configuration parameter: can be overwritten by the init block of an anonymous subclass. The code of this library will be included in the generated d2d-xslt output.
    • used

      boolean used
      Flag to ensure single use.
    • msg

      Evident
    • msg_c

      protected final MessageCounter msg_c
      Evident
    • verbosity

      final int verbosity
    • target

      protected String target
      The name of the target format for filtering the rules from the modules.
    • xtarget

      protected String xtarget
      The name of the target format prefixed by "to_"
    • printwriter

      protected PrintWriter printwriter
      The output channel for the generated xslt-d2d source.
    • generatedDoc

      protected XMLDocumentIdentifier generatedDoc
      The document identifier used for all locations into the generated text. Is set by the caller.
    • linenumber

      protected int linenumber
      The current line number written to the output.
    • rulecount

      protected int rulecount
      Number of extracted rules, for diagnosis only.
    • defsVisited

      protected Set<String> defsVisited
      Set of all source text paths which have already been written out. These are the identifiers of the "static source path" = "raw definitions".
    • written

      protected Set<String> written
      Set of all XML tags for which a "<xslt:template match="TAG">" has been synthesized. Each XML tag is written at most once. This implies that each raw definition is written at most once.

      ATTENTION can currently not deal with two different raw definitions with the same XML tag. In this case, one of these is selected without further notice.

      (Since the ns-prefices are unique and global, comnparison of qnames stands for comparison of NamespacesNames.)

    • stringpos2orig

      Map constructed during output which maps the module source location to the generated output source.
    • namespaces

      final Map<String,String> namespaces
      Map of all prefices to namspace Uris, as collected by Def2Xslt3.CollectNs
    • namespaceOrig

      final Map<String,ResolvedModule> namespaceOrig
      Only needed to inform about conflicts:
  • Constructor Details

  • Method Details

    • extract

      public void extract(String target, @Opt @Opt String tdom, @Opt @Opt String topElement, XMLDocumentIdentifier docid, @Opt @Opt LocationMap<XMLDocumentIdentifier,XMLDocumentIdentifier> stringpos2orig, String genComment, PrintWriter printwriter, ResolvedModule... modules)
      Entry method for conversion. The result is written as a d2d source text to the printwriter.
      Parameters:
      target - the name of the target format for filtering the rules stored with the input models.
      tdom - from which to get the Dtd for the later inegrated parsing of xslt and target elements. Can be ==null for unstructured targets = non-xml output, or for xslt to be used with another xslt processor. In this case "target" will be the only indication in the extracted code.
      topElement - inserted in the "d2d xslt" declaration for later xslt parsing If ==null then it signals unstructured targets = non-xml output.
      docid - the identifier to identify the generated lines
      stringpos2orig - an OUTPUT parameter which will hold the relation from generated lines in the extracted ".xstl.d2d" source to the to original lines in the ".ddf"-file. This is needed for a later translation of the Location in error messages.
      genComment - generation comment, supplied by the caller, added to the beginning of the ouput (as NON-doc comment).
      printwriter - drain for the resulting source text.
      modules - list of d2d modules; all of their public definitions shall be translated
    • putSeparator

      protected void putSeparator()
      Write an xslt element "&lt;<xslt:toplevel>" to the output. This is our extension to xslt and causes the end of a template contents, so that it will not swallow immediately following variables, etc., when parsing it later.
    • output

      protected void output(CheckedList<LocString> docu)
      Copy the documentaton line block to the output and update the location map. (Template header and footer are written before and after this method invocation.)
    • action

      public void action(Definition def)
      Overrides:
      action in class SinglePhase
    • action

      public void action(Reference ref)
      Overrides:
      action in class SinglePhase