[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

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?
0
emsenthil
Asked:
emsenthil
1 Solution
 
BigRatCommented:
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 :-

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

At least with this method one doesn't need files to hold the data, it can come from strings.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now