Nagaraj Prabhu
Nagaraj Prabhu

Reputation: 1

How to modify xslt stylesheet using java?

I want to modify some element values like font size,color in xslt through java. I tried with following java code

File xslFile = new File("D:/header.xsl");
     System.out.println(xslFile.getPath());
     javax.xml.transform.Source xsltSource = new javax.xml.transform.stream.StreamSource(xslFile); 
     javax.xml.transform.TransformerFactory transformerFactory = javax.xml.transform.TransformerFactory.newInstance();
     javax.xml.transform.Transformer xsltTransformer = transformerFactory.newTransformer(xsltSource);
     xsltTransformer.setParameter("clr", "red");

The java code building successfully but the value is not reflecting into xsl stylesheet.

Upvotes: 0

Views: 324

Answers (1)

forty-two
forty-two

Reputation: 12817

Using parameter passing this way does not change the original stylesheet, just the in memory representation of it. But, assuming that you have a

<xsl:parameter name="clr">blue</xsl:parameter>

declaration at the top level of your stylesheet, your code would set the value of that parameter to red.

Upvotes: 1

Related Questions