org.vishia.xml
Class Xslt

java.lang.Object
  extended by org.vishia.xml.Xslt

public class Xslt
extends java.lang.Object

vishia XSLT Translator.

This translator calls the java-standard XSLT-engine defined with javax.xml.transform.TransformerFactory. The cmdLine-option -xslt:TRANSFORMER determines, which Transformer is used. The default-value is net.sf.saxon.TransformerFactoryImpl, therefore this Transformer is recommended to use. It should be provided by the adequate jar-File specified in the java's-CLASSPATH.

The vishia-XSLT prepares some inputs before calling the outside given Transformer:

Multiple inputs:
More as one XML-Inputfile is able to use as input. All input file-contents are disposed after a internal created < root> root-Element. It means, the translation file have to be regard this additional < root> root-Element. Write:

     < xsl:apply-templates match="/root" >
        ....
     
   
instead the often used
     < xsl:apply-templates match="/" >
        ....
     
   


Replacing of spaces of input:
The XML file representation may contain any white spaces (more as one space, line feed, indentation) between the XML-elements. It is a method of beautification of the appearance of the file content. The white spaces may be included by any XML-writer independent of the meaning of the content. But if the input should present a text with formatted inner elements (maybe XHTML), the white spaces may be interpreted as really text characters. The class XmlExtensions contains a static method org.vishia.xml.XmlExtensions.readXmlFileTrimWhiteSpace(File) which is used here if an input is designated with the cmdLine option -j:FILE.

Expansion of wikistyle:
This feature is not implemented yet. The conversion of WikistyleTextToSimpleXml is implemented instead in the ZBNF2Xml-conversion (class ZbnfXmlOutput and in the class CorrectHref for documentation generation. It was contained here in the past. It isn't supported yet, because the conversion routine is changed using the XmlNode, which is not directly compatible with JDOM. An adaption is existing in the XmlNodeJdom, but it isn't used here yet.

Beautification of output:
This feature was implemented here in the past before using the SAXON-XSLT. But the SAXON writes the file in an adequate style itself.

A beautification should generate indentation automatically. But it should regard textual contents: If any element contains a textual content, its whole content should be written in one line to prevent additional white spaces which may be confused the textual content. Such an XML-writer is implemented in org.vishia.xml.XmlExtensions.writeXmlBeautificatedTextFile(Element, File, Charset)}. This writer uses JDOM as input. This is the older implementation. A newer implementation of this feature is present in SimpleXmlOutputter.


Nested Class Summary
(package private)  class Xslt.CmdLine
          The inner class CmdLine helps to evaluate the command line arguments and show help messages on command line.
protected  class Xslt.Parameter
           
 
Field Summary
protected  boolean bWikiFormat
          Set on command line option.
(package private)  MainCmd_ifc console
          Aggregation to the Console implementation class.
protected  java.util.List<Xslt.Parameter> params
           
protected  java.lang.String sFileOut
          Cmdline-argument, set on -y option.
protected  java.lang.String sFileXslp
          CmdLine-argument set on -p option: XSLT-File pre-converted with Xsltpre.
protected  java.lang.String sFileXslt
          CmdLine-argument set on -t option: XSLT-File for Transformer.
protected  java.lang.String sTransformer
          Class which is used by the javax.xml.transform.TransformerFactory It is set with System.setProperty("javax.xml.transform.TransformerFactory",
protected  XmlMReader xmlMReader
          Instance to process input files.
 
Constructor Summary
Xslt()
           
 
Method Summary
private  void execute()
          Executes the task of this class.
private  java.io.File genXslFromXslp()
          Converts the Xslt-file using Xsltpre
static void main(java.lang.String[] args)
          main started from java.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sFileOut

protected java.lang.String sFileOut
Cmdline-argument, set on -y option. Outputfile to output something.


sFileXslt

protected java.lang.String sFileXslt
CmdLine-argument set on -t option: XSLT-File for Transformer. Either it is the primary file, or, if sFileXslp is given, it is the name of the output file.


sFileXslp

protected java.lang.String sFileXslp
CmdLine-argument set on -p option: XSLT-File pre-converted with Xsltpre. If it is null, the is used as input. . NOTE: If the XSLT-File given in sFileXslt- element is newer as this given file, the first one will not overwritten by this given file. This feature may be able to use for fine adjustments of content while debugging a script.


params

protected java.util.List<Xslt.Parameter> params

sTransformer

protected java.lang.String sTransformer
Class which is used by the javax.xml.transform.TransformerFactory It is set with System.setProperty("javax.xml.transform.TransformerFactory", ...);


bWikiFormat

protected boolean bWikiFormat
Set on command line option. If true, after xslt translation the output tree is evaluate for elements with attribute expandWikistyle or WikiFormat. This elements are expanded.


xmlMReader

protected final XmlMReader xmlMReader
Instance to process input files. This instance holds informations about input files with several reading conditions and contains a xml parser call.


console

MainCmd_ifc console
Aggregation to the Console implementation class.

Constructor Detail

Xslt

public Xslt()
Method Detail

main

public static void main(java.lang.String[] args)
main started from java.

Command line options:

      "invoke { -[i|j|k]:INPUT } [-t:XSLT] [-p:XSLP] -y:OUTPUT [-xslt:TRANSFORMER]");
      "-i:INPUT-XML-file");
      "-j:INPUT-XML-file, Whitespaces will replaced with 1 space");
      "-t:XSLT: xsl-script XML2-compatible, it is output if -p:XSLP is given");
      "-p:XSLP: Script pretranslated with Xsltpre, than -t:XSLT will be created if older.");
      "         If no option -t:XSLT is given, XSLT will be created parallel with .xsl as extension.");
      "-y:OUTPUT-file");
      "-xslt:TRANSFORMER Set the class for Transformer-Implementation. Default is " + sTransformer);
      


execute

private void execute()
              throws javax.xml.parsers.ParserConfigurationException,
                     java.io.FileNotFoundException,
                     org.xml.sax.SAXException,
                     java.io.IOException,
                     javax.xml.transform.TransformerException,
                     XmlException
Executes the task of this class.

Throws:
javax.xml.parsers.ParserConfigurationException
java.io.IOException
org.xml.sax.SAXException
java.io.FileNotFoundException
javax.xml.transform.TransformerException
XmlException

genXslFromXslp

private java.io.File genXslFromXslp()
Converts the Xslt-file using Xsltpre

Returns: