Class Transform


  • public class Transform
    extends java.lang.Object
    Handy wrapper for an XSLT transformation performed using JAXP/Trax. Note that transformation is not actually performed until a call to getResultXXX method, and Templates are not used.
    Examples and more at xmlunit.sourceforge.net
    • Constructor Summary

      Constructors 
      Constructor Description
      Transform​(java.lang.String input, java.io.File stylesheet)
      Create a transformation using String input XML and stylesheet in a File
      Transform​(java.lang.String input, java.lang.String stylesheet)
      Create a transformation using String input XML and String stylesheet
      Transform​(javax.xml.transform.Source inputSource, javax.xml.transform.Source stylesheetSource)
      Create a transformation using Source input XML and Source stylesheet
      Transform​(org.w3c.dom.Node sourceNode)
      Create a transformation that allows us to serialize a DOM Node
      Transform​(org.w3c.dom.Node sourceNode, java.io.File stylesheet)
      Create a transformation from an input Node and stylesheet in a File
      Transform​(org.w3c.dom.Node sourceNode, java.lang.String stylesheet)
      Create a transformation from an input Node and stylesheet in a String
      Transform​(org.xml.sax.InputSource input, java.io.File stylesheet)
      Create a transformation using InputSource input XML and stylesheet in a File
      Transform​(org.xml.sax.InputSource input, org.xml.sax.InputSource stylesheet)
      Create a transformation using InputSource input XML and InputSource stylesheet
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearParameters()
      Clear parameters used for the transformation
      java.lang.Object getParameter​(java.lang.String name)
      See a parameter used for the transformation
      org.w3c.dom.Document getResultDocument()
      Perform the XSLT transformation specified in the constructor
      java.lang.String getResultString()
      Perform the XSLT transformation specified in the constructor
      void setErrorListener​(javax.xml.transform.ErrorListener errorListener)
      Set the ErrorListener for the transformation
      void setOutputProperties​(java.util.Properties outputProperties)
      Override output properties specified in the transformation stylesheet
      void setOutputProperty​(java.lang.String name, java.lang.String value)
      Override an output property specified in the transformation stylesheet
      void setParameter​(java.lang.String name, java.lang.Object value)
      Add a parameter for the transformation
      void setURIResolver​(javax.xml.transform.URIResolver uriResolver)
      Set the URIResolver for the transformation
      protected void transformTo​(javax.xml.transform.Result result)
      Perform the actual transformation
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Transform

        public Transform​(java.lang.String input,
                         java.lang.String stylesheet)
        Create a transformation using String input XML and String stylesheet
        Parameters:
        input -
        stylesheet -
      • Transform

        public Transform​(java.lang.String input,
                         java.io.File stylesheet)
        Create a transformation using String input XML and stylesheet in a File
        Parameters:
        input -
        stylesheet -
      • Transform

        public Transform​(org.xml.sax.InputSource input,
                         org.xml.sax.InputSource stylesheet)
        Create a transformation using InputSource input XML and InputSource stylesheet
        Parameters:
        input -
        stylesheet -
      • Transform

        public Transform​(org.xml.sax.InputSource input,
                         java.io.File stylesheet)
        Create a transformation using InputSource input XML and stylesheet in a File
        Parameters:
        input -
        stylesheet -
      • Transform

        public Transform​(org.w3c.dom.Node sourceNode)
        Create a transformation that allows us to serialize a DOM Node
        Parameters:
        source -
      • Transform

        public Transform​(org.w3c.dom.Node sourceNode,
                         java.lang.String stylesheet)
        Create a transformation from an input Node and stylesheet in a String
        Parameters:
        sourceNode -
        stylesheet -
      • Transform

        public Transform​(org.w3c.dom.Node sourceNode,
                         java.io.File stylesheet)
        Create a transformation from an input Node and stylesheet in a File
        Parameters:
        sourceNode -
        stylesheet -
      • Transform

        public Transform​(javax.xml.transform.Source inputSource,
                         javax.xml.transform.Source stylesheetSource)
        Create a transformation using Source input XML and Source stylesheet
        Parameters:
        inputReader -
        stylesheetReader -
    • Method Detail

      • transformTo

        protected void transformTo​(javax.xml.transform.Result result)
                            throws javax.xml.transform.TransformerException
        Perform the actual transformation
        Parameters:
        result -
        Throws:
        javax.xml.transform.TransformerException
      • getResultString

        public java.lang.String getResultString()
                                         throws javax.xml.transform.TransformerException
        Perform the XSLT transformation specified in the constructor
        Returns:
        the result as a String
        Throws:
        javax.xml.transform.TransformerException
      • getResultDocument

        public org.w3c.dom.Document getResultDocument()
                                               throws javax.xml.transform.TransformerException
        Perform the XSLT transformation specified in the constructor
        Returns:
        the result as a DOM Document
        Throws:
        javax.xml.transform.TransformerException
      • setOutputProperty

        public void setOutputProperty​(java.lang.String name,
                                      java.lang.String value)
        Override an output property specified in the transformation stylesheet
        Parameters:
        name -
        value -
      • setOutputProperties

        public void setOutputProperties​(java.util.Properties outputProperties)
        Override output properties specified in the transformation stylesheet
        Parameters:
        outputProperties -
        See Also:
        Transformer.setOutputProperties(java.util.Properties)
      • setParameter

        public void setParameter​(java.lang.String name,
                                 java.lang.Object value)
        Add a parameter for the transformation
        Parameters:
        name -
        value -
        See Also:
        Transformer.setParameter(java.lang.String, java.lang.Object)
      • getParameter

        public java.lang.Object getParameter​(java.lang.String name)
        See a parameter used for the transformation
        Parameters:
        name -
        Returns:
        the parameter value
        See Also:
        Transformer.getParameter(java.lang.String)
      • clearParameters

        public void clearParameters()
        Clear parameters used for the transformation
        See Also:
        Transformer.clearParameters()
      • setURIResolver

        public void setURIResolver​(javax.xml.transform.URIResolver uriResolver)
        Set the URIResolver for the transformation
        See Also:
        Transformer.setURIResolver(javax.xml.transform.URIResolver)
      • setErrorListener

        public void setErrorListener​(javax.xml.transform.ErrorListener errorListener)
        Set the ErrorListener for the transformation
        See Also:
        Transformer.setErrorListener(javax.xml.transform.ErrorListener)