Package javax.xml.transform

Examples of javax.xml.transform.Templates


  public static void exampleParam(String sourceID,
                                  String xslID)
    throws TransformerException, TransformerConfigurationException
  {
    TransformerFactory tfactory = TransformerFactory.newInstance();
    Templates templates = tfactory.newTemplates(new StreamSource(xslID));
    Transformer transformer1 = templates.newTransformer();
    Transformer transformer2 = templates.newTransformer();

    transformer1.setParameter("a-param",
                              "hello to you!");
    transformer1.transform(new StreamSource(sourceID),
                           new StreamResult(new OutputStreamWriter(System.out)));
View Full Code Here


  public static void exampleOutputProperties(String sourceID, String xslID)
    throws TransformerException, TransformerConfigurationException
  {

    TransformerFactory tfactory = TransformerFactory.newInstance();
    Templates templates = tfactory.newTemplates(new StreamSource(xslID));
    Properties oprops = templates.getOutputProperties();

    oprops.put(OutputKeys.INDENT, "yes");

    Transformer transformer = templates.newTransformer();

    transformer.setOutputProperties(oprops);
    transformer.transform(new StreamSource(sourceID),
                          new StreamResult(new OutputStreamWriter(System.out)));
  }
View Full Code Here

      // The TransformerFactory will compile the stylesheet and
      // put the translet classes inside the Templates object
      TransformerFactory factory = TransformerFactory.newInstance();
            factory.setAttribute("generate-translet", Boolean.TRUE);
      Templates templates = factory.newTemplates(stylesheet);
        }
  catch (Exception e) {
            System.err.println("Exception: " + e);
      e.printStackTrace();
        }
View Full Code Here

    try
    {
      // Instantiate the TransformerFactory, and use it along with a SteamSource
      // XSL stylesheet to create a translet as a Templates object.
      TransformerFactory tFactory = TransformerFactory.newInstance();
      Templates translet = tFactory.newTemplates(new StreamSource(xslInURI));
   
      // Perform each transformation
      doTransform(translet, "todo.xml", "todo.html");
      System.out.println("Produced todo.html");
   
View Full Code Here

  {
    compiledTemplatesCache.put(name,getTemplates(xslIs));
  }
  public String getQueryAsXmlString(Properties formProperties,String queryTemplateName) throws SAXException, IOException, ParserConfigurationException, TransformerException
  {
    Templates ts= compiledTemplatesCache.get(queryTemplateName);
    return getQueryAsXmlString(formProperties, ts);
  }
View Full Code Here

    return getQueryAsXmlString(formProperties, ts);
  }
 
  public Document getQueryAsDOM(Properties formProperties,String queryTemplateName) throws SAXException, IOException, ParserConfigurationException, TransformerException
  {
    Templates ts= compiledTemplatesCache.get(queryTemplateName);
    return getQueryAsDOM(formProperties, ts);
  }
View Full Code Here

    try {
      // Create transformer factory
      TransformerFactory factory = TransformerFactory.newInstance();

      // Use the factory to create a template containing the xsl file
      Templates template = factory.newTemplates(new StreamSource(
          new FileInputStream(xslfile)));

      // Use the template to create a transformer
      Transformer xformer = template.newTransformer();
     
      // passing 2 parameters
      String branch = outfile.getParentFile().getCanonicalPath().substring(root.length());
      branch = branch.replace(File.separatorChar, '/');
      StringBuffer path = new StringBuffer();
View Full Code Here

    }
    removeSkipEvaluation(context);

    try {
      DOMSource domSource = getDOMSource(context);
      Templates templates = getTemplates(context);
      Transformer transformer = templates.newTransformer();
      setParams(transformer, context);

      StringWriter writer = new StringWriter();
      transformer.transform(domSource, new StreamResult(writer));
      String result = writer.toString();
View Full Code Here

    return domSource;
  }

  private Templates getTemplates(TransformContext context) throws Exception {
    Object xsltValue = evaluateExpression(xslt, context);
    Templates templates = null;

    if (xsltValue instanceof String) {
      templates = parseXslt((String) xsltValue);
    } else if (xsltValue instanceof Templates) {
      templates = (Templates) xsltValue;
View Full Code Here

    public static Document transform(Map<String, Object> context, Map<String, Object> params)
        throws GeneralException, IOException, TransformerConfigurationException, TransformerException {
        Document outputDocument = null;
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Templates translet = null;
        String templateName = (String)context.get("templateName");
        if (UtilValidate.isNotEmpty(templateName)) {
            translet = xslTemplatesCache.get(templateName);
        }

        if (translet == null ) {
            String templateUrl = (String)context.get("templateUrl");
            String templateString = (String)context.get("templateString");
            Document templateDocument = (Document)context.get("templateDocument");
            Source templateSource = getSource(templateDocument, templateUrl, templateString);
            translet = tFactory.newTemplates(templateSource);
            if (UtilValidate.isNotEmpty(templateName)) {
                    xslTemplatesCache.put(templateName, translet);
            }
        }
        if (translet != null ) {
            Transformer transformer = translet.newTransformer();
            if (params != null) {
                for (Map.Entry<String, Object> entry: params.entrySet()) {
                       String key = (String)entry.getKey();
                    Object val = entry.getValue();
                    transformer.setParameter(key, val);
View Full Code Here

TOP

Related Classes of javax.xml.transform.Templates

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.