p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

xslt thread: Using parameter in apply-templates select

Message #1 by "Dave Isaacs" <dave.isaacs@e...> on Thu, 5 Sep 2002 19:14:41
Well, yes, passing in a node-set from Java is probably a way to do it.  I 
simply do not know how.  The available documentation is rather thin.

Does the example below help? (written quickly, taken mostly from a trax 


import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.*;

import java.io.StringReader ;
import org.xml.sax.InputSource;

import org.apache.xalan.* ;
import org.w3c.dom.Node ;

public class Untitled1 {

  public Untitled1() throws Exception {

    DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
    TransformerFactory tfactory = TransformerFactory.newInstance();
    Transformer transformer  = 
        tfactory.newTransformer(new StreamSource("my.xsl"));

    StringReader myparams = new StringReader( 
         "<x><your/>nodes<here/></x>") ;
    org.w3c.dom.Node paramsnode = 
        docBuilder.parse(new InputSource(myparams));

    transformer.setParameter("my-param",paramsnode) ;

    transformer.transform(new StreamSource("my.xml"),
                       new StreamResult(System.out));

  public static void main(String[] args) throws Exception{
    Untitled1 untitled11 = new Untitled1();

  Return to Index