Passing Parameters Using JAVA, XSL, XML

Greetings!

I have a question concerning passing parameters using Java.  I have a function that takes the XSL parameters, and is supposed to set them for processing.  However, I continue to receive various befuddling errors upon compilation.

Here is the Java function that does the Transformer actions:

        public void appendToResponse(WOResponse response, WOContext context) {
                response.setContentEncoding("UTF8");
                super.appendToResponse(response, context);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();

                try {
     
                TransformerFactory tFactory = TransformerFactory.newInstance();
                StreamSource xslSource = new StreamSource("http://here.is.my.fullpath.to/File.xsl");
     
                Transformer transformer = tFactory.newTransformer(xslSource);

                StreamSource inXML = new StreamSource(getXmlSource());
                StreamResult outXML = new StreamResult(baos);
                transformer.setParameter("BatchIndex", BatchIndex);                < =====   why doesn't this work?
                transformer.setParameter("SessionID", SessionID);                       < =====   why doesn't this work?
                transformer.setParameter("Criteria", Criteria);                                 < =====   why doesn't this work?
                transformer.setParameter("BatchCount", BatchCount);                            < =====   why doesn't this work?
                transformer.transform(inXML, outXML);
                } catch (TransformerException e) {
                        System.err.println(e);
                }
                response.setContent(new NSData(baos.toByteArray()));
                response.setHeader("text/html; charset=UTF-8 encoding=UTF-8", "content_type");
     }

I also have an additional  function in another class, that is supposed to take the formValueForKey values.

     public WOComponent renderXMLAction(){

     WORequest request = request();
     String xmlFile=(String)request().formValueForKey("BatchIndex");                < =====   why doesn't this work?
     String xmlFile=(String)request().formValueForKey("BatchCount");                   < =====   why doesn't this work?
     String xmlFile=(String)request().formValueForKey("Criteria");                           < =====   why doesn't this work?
     String xmlFile=(String)request().formValueForKey("SessionId");                           < =====   why doesn't this work?
 
     SearchResults nextPage=(SearchResults)pageWithName("SearchResults");
     nextPage.setXmlSource(xmlFile);  
     return nextPage;

    }

Any advice or guidance is greatly appreciated!

Best regards,
Jamie
jmc430Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sudhakar_koundinyaCommented:
For your second issue

I see same variable name for all the requests
>>String xmlFile=(String)request().formValueForKey("BatchIndex");          
>>String xmlFile=(String)request().formValueForKey("BatchCount");              

And also check the instance that you are getting from request.
As an example include this debugging statement.
System.err.println(request().formValueForKey("BatchIndex").getClass());

If the result is not java.lang.String you need to recheck your code

Best Regards
Sudhakar
0
sudhakar_koundinyaCommented:


If your requests are conditional, you should put them in conditions

String xmlFile=(String)request().formValueForKey("BatchIndex");          
if(xmlFile==null||xmlFile.length()==0)
{
xmlFile=(String)request().formValueForKey("BatchCount");            
}

Is that what you are expecting??

Regards
Sudhakar
0
sudhakar_koundinyaCommented:
>>transformer.setParameter("BatchIndex", BatchIndex);
>>transformer.setParameter("SessionID", SessionID);

Check if BatchIndex,SessionID are null or valid objects. Similarly you should check other objects also

Best Regards
Sudhakar Chavali
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

jmc430Author Commented:
I'm trying to append all those values, (BatchCount, BatchIndex, SessionID, Criteria), into the XSLT transform.

These parameters will not be null in any instances..

0
sudhakar_koundinyaCommented:
Ok can you post the compilation errors

Regards
Sudhakar Chavali
0
jmc430Author Commented:
Hi Sudhakar,

I'm only getting one error:

javax.xml.transform.TransformerException:java.net.MalformedURLException

I found online that this means the "text of a stylesheet to an interface that was expecting a URI." but I don't know what this means.

Thanks for helping me ...

Best regards,
Jamie
0
sudhakar_koundinyaCommented:
Generally I code like this -> Directly uses Sun's JDK API
public Transformer getTransformer(String xslFileName)
{
    try
   {
      System.err.println(xslFileName);
      Transformer transformer = null;
      StreamSource source=new StreamSource(xslFileName);
      transformer = transformerfactory.newTransformer(source);
      return transformer;
    }
    catch (Exception ex)
   {
      ex.printStackTrace();
      return null;
    }
}


Uses xlst.jar


 public Transformer getTransformer(String xslFileName) {
    try {
      System.err.println(xslFileName);
      Transformer transformer = null;
      Templates templates = null;
      StreamSource source=new StreamSource(xslFileName);
      templates = transformerfactory.newTemplates(source);
      transformer = templates.newTransformer();
      return transformer;
    }
    catch (Exception ex) {
      ex.printStackTrace();
      return null;
    }
0
jmc430Author Commented:
I don't think the transformation itself is giving me issues ..

Basically my transformation works on the first transform (when I first submit parameters to be processed by the XSL).  However, on the second transform, when I want to take all the parameters (plus the newly inputted parameters) I want to pass the new parameters to the same transform.

I want to be able to have a request.setParameter() and a request.getParameter() somewhere (as in JSP) but I do not know how to achieve this.

I'm getting this error as well:

javax.xml.transform.Transformer.Exception: The declaration for the entity "HTML.Version" must end with '>'.

Thanks for helping me..
0
objectsCommented:
> javax.xml.transform.TransformerException:java.net.MalformedURLException

looks more like a runtime error rather than a compile error
and the problem is more likely in your xml/xsl files.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jmc430Author Commented:
thanks for pointing me in the right direction.

:)
0
objectsCommented:
no worries :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

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.