How to pass a Document object as a parameter to XSLT

I am executing a XSLT from Java using this code ::

        DocumentBuilder builder;
        InputStream defInputStream = this.getClass().getClassLoader().getResourceAsStream("definitionsdb.xml");
        Document definitionsDB = builder.parse(defInputStream);

            Source xslSource = new StreamSource(inputXMLFile);
            Result xmlResult = new StreamResult(xmlOutputFileWriter);
            xmlTransformer.setParameter("inputFile", definitionsDB);
            xmlTransformer.transform(xslSource, xmlResult);

As you can see, apart from the StreamSource input xml file, I am sending another XML file as a parameter to the XSLT.

I receive the file in XSLT using the <xsl:param name="inputFile"/>

But then, I am not able to use the variable as a normal nodeset variable... like $inputFile/Definition/node1 ...

Any solution, on how to solve it?
Who is Participating?
BigRatConnect With a Mentor Commented:
XSLT (as a standard) only allows reference to document via file names, which it resolves and loads. I know of no method of passing the transformer a node-set in a document object. This of course makes it difficult to include XML or XSL source which one has in a string.

The only suggestion I can make is to load an xml string containing two nodes containing the relevant parts :-

        <part id="1">....contents of the first file</part>
        <part id="2">....contents of the second file</part>
        .... and so on...

At least with this method one doesn't need files to hold the data, it can come from strings.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.