import javax.xml.transform.Templates;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;
import java.io.StringReader;
import java.util.Properties;

public class SimplifiedTest {
    public static void main(String[] args) throws TransformerConfigurationException {
        String xslData = "<?xml version='1.0'?>"
                + "<xsl:stylesheet"
                + " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'"
                + " version='1.0'"
                + ">\n"
                + "   <xsl:output method='html'/>\n"
                + "   <xsl:template match='/'>\n"
                + "     Hello World! \n"
                + "   </xsl:template>\n"
                + "</xsl:stylesheet>";

        System.out.println(xslData);

        Templates templates = null;
        try {

            /* Try to create Templates object for the stylesheet */
            templates = TransformerFactory.newInstance().newTemplates(new StreamSource(new StringReader(xslData)));
        } catch (TransformerConfigurationException e) {
            throw e;
        }

        Properties properties = templates.getOutputProperties();
        String[] prNames = new String[]{"method", "version", "indent", "media-type"};
        String[] prValues = new String[]{"html", "4.0", "yes", "text/html"};

        try {
            checkProperties(properties, prNames, prValues);
        } catch (Exception e) {
            System.err.println("Failed. " + e);
            return;
        }
        System.out.println("Passed.");
    }

    private static void checkProperties(Properties properties, String[] prNames, String[] prValues)
            throws Exception {
        int n = prNames.length;

        for (int i = 0; i < n; i++) {
            String value = properties.getProperty(prNames[i]);
            if (!value.equals(prValues[i])) {
                throw new Exception(prNames[i] + ":- actual: " + value + ", expected: " + prValues[i]);
            }
            System.out.println(prNames[i] + ":- actual: " + value + ", expected: " + prValues[i]);
        }
    }
}

