File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Help on setPrarameter() fror transformer.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Help on setPrarameter() fror transformer.." Watch "Help on setPrarameter() fror transformer.." New topic

Help on setPrarameter() fror transformer..

Raj Sethi

Joined: Mar 11, 2001
Posts: 9
Hi All
I have the following code
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
public class TestTransform

private static String RULES=
"<?xml version=\"1.0\"?>" +
"<xsl:stylesheet xmlns:xsl=\"\" version=\"1.0\">" +
" <xsl:template match=\"*\">" +
" <xsl:element name=\"{name()}\" >" +
" <xsl:call-template name=\"template-name\">" +
" </xsl:call-template>" +
" </xsl:element>" +
" </xsl:template> " +
"<xsl:template name =\"template-name\">" +
" <xsl aram name=\"first\">First </xsl aram>" +
" <xsl aram name=\"last\">Name </xsl aram>" +
" <xsl:value-of select=\"$first\"/>" +
" <xsl:value-of select=\"$last\"/>" +
"</xsl:template>" +
private static String SOURCE="<a>test</a>";
public static void main(String args[])
Source xmlsource = new StreamSource(new ByteArrayInputStream(SOURCE.getBytes()));
TransformerFactory factory = TransformerFactory.newInstance();
ByteArrayOutputStream result = new ByteArrayOutputStream();
Transformer transformer = null;
transformer = factory.newTransformer(new StreamSource(new ByteArrayInputStream(RULES.getBytes())));
System.out.println("get parameter first:" +transformer.getParameter("first"));
transformer.transform(xmlsource,new StreamResult(result));

System.out.println("output :"+result.toString());
catch (Exception e)
System.out.println("error "+e.getMessage());



The out put is FirstName instead of RajName //because I'm setting param first to Raj at //transformer.setParameter("first","Raj");
Where I am getting it wrong appreciate any help..
Alexander Sack

Joined: Jun 29, 2001
Posts: 3

from java it seems fine; but you have to define the parameter
in a global scope ( child of the xsl:stylesheet tag ) not
in local scope (child of xsl:template element)

Alexander Sack

I agree. Here's the link:
subject: Help on setPrarameter() fror transformer..
It's not a secret anymore!