oh...yeah...don't forget to import all classes you are using :)
Main Topics
Browse All TopicsHello..
I have go thru some study on how can I implement xml-xslt to do text translation for my project.
But I still stuck understanding some example given in the tutorial. I'm not sure am I in the right track to use xml-xslt to translate some text label in jsp pages to different languages based on user selection. If not please suggest.
FYI the language code is stored in locale session. if I have this xml, how can I use xslt and display the output in jsp?
label.xml
-----------
<?xml version="1.0"?>
<locale>
<userid>
<en_us>User Name</en_us>
<de>Benutzername</de>
</userid>
<password>
<en_us>Password</en_us>
<de>Passwort</de>
</password>
<logonbutton>
<en_us>Logon</en_us>
<de>Anmelden</de>
<logonbutton>
--------------------------
Thanks in advance
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
FYI again, my jsp should be like this. I want the label "User ID" and "Password" is change accoudingly to user language selection based on xml file.
logonpage.jsp
--------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="37%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="34%">User ID</td>
<td width="2%">:</td>
<td width="64%"><input type="text" name="textfield"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input type="text" name="textfield2"></td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="Logon">
</p>
</body>
</html>
dualsoul,
Is this correct fro sample.jsp??
sample.jsp
--------------------------
<%@page import ="java.lang.*" %>
<%@page import ="java.util.*" %>
<%@page import ="java.io.*" %>
<html><head></head>
<body>
<%
// Step 1: Get XML
String xml = "label.xml"; //get some xml here to String (just for instance)
//Step 2: prepare source and result streams
StreamSource source=new StreamSource(new StringReader(xml));
//set stylesheet here
StreamSource stylesheet=new StreamSource(this.getClass
StringWriter outHtml=new StringWriter();
StreamResult result=new StreamResult(outHtml);
//Step 3: do transformation
TransformerFactory transFactory=TransformerFa
Transformer transformer=transFactory.n
transformer.transform(sour
//Step 4: print out the result
out.println(outHtml.toStri
%>
</body>
</html>
--------------------------
ok dualsoul, after some modification, I solve the import class porblem but then it produce this error:
exception
org.apache.jasper.JasperEx
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at javax.servlet.http.HttpSer
at org.apache.catalina.core.A
at org.apache.catalina.core.A
What should I do?
>What should I do?
it seems you trying to point your XSLT file - in wrong location:
..........................
StreamSource stylesheet=new StreamSource(this.getClass
..........................
check the path.
and String xml = "label.xml";
this is not XML filename, it's XML it self. If you want to use file, this should be:
..........................
// Step 1: Get XML
String xml = "label.xml"; //filename here
//Step 2: prepare source and result streams
StreamSource source=new StreamSource(this.getClass
..........................
And again don't forget to set up correct path for XML file.
> I want the label "User ID" and "Password" is change accoudingly to user language selection >based on xml file.
you should write XSLT which transform your XML to Form, and insert it in your .jsp as i show you. Do you need help with it?
By the way if you only need localization of your webapp, you can easily do it without XML, check the JSTL (Java Standart Tags Library) - it has support for localization.
> I want the label "User ID" and "Password" is change accoudingly to user language selection >based on xml file.
you should write XSLT which transform your XML to Form, and insert it in your .jsp as i show you. Do you need help with it?
By the way if you only need localization of your webapp, you can easily do it without XML, check the JSTL (Java Standart Tags Library) - it has support for localization.
by the way , is this xslt id correct ?
label.xsl
--------------------------
<xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.o
<xsl:template match="/">
<h1>
<xsl:value-of select="//author"/>
</h1>
<h2>
<xsl:value-of select="//title"/>
</h2>
</xsl:template>
</xsl:stylesheet>
--------------------------
>And also I still not understand the concept of localization.
Localization - is the process, when your app can operate with different languages, according to clients locale. That's what you want to do.
heck the tutrorial on localization at java.sun.com
About XSLT, which values you want to use? <en-us> or <de> ?
ok, i'll show it a bit later - a'm busy at work now.
But i recomend you to read this: http://java.sun.com/docs/b
before you go with your xml solution.
Java has native support fot localization, and all work you try to do, can be much easier. Really read the trail first.
yes i've read it... I understand the proses... now i'm in a process of combining the class with jsp using javabeans.
Then how about the xslt? I think we still need to use xslt with xml. I understood that with xslt, we can generate any format of document from xml. therefore using xslt is more flexible. I need to know about transformation xml using xslt.
pls consult..
>now i'm in a process of combining the class with jsp using javabeans.
look, don't fuzzy :), first find and read about JSTL (at java.sun.com ) - it will make your work much easier :)
> I need to know about transformation xml using xslt.
hm..so what do you want to know? how to do the task you suggested at first? or something else?
I show you how to to transform within jsp above , not?
>therefore using xslt is more flexible.
i think it will be too complex for localization, and you know XSLT is rather slow on Java platform comparing to JSP, so you should have some more reasons to use it, not only localization.
Business Accounts
Answer for Membership
by: dualsoulPosted on 2004-01-28 at 06:10:29ID: 10218098
easy :) just do XSLT transform as in standalone java app. See: (sample.jsp)
........
().getReso urceAsStre am("myStyl esheet.xsl ));
ctory.newI nstance(); ewTransfor mer(styles heet); ce,result) ;
ng()); ........
..........................
<html><head></head>
<body>
<%
// Step 1: Get XML
String xml = "..."; //get some xml here to String (just for instance)
//Step 2: prepare source and result streams
StreamSource source=new StreamSource(new StringReader(xml));
//set stylesheet here
StreamSource stylesheet=new StreamSource(this.getClass
StringWriter outHtml=new StringWriter();
StreamResult result=new StreamResult(outHtml);
//Step 3: do transformation
TransformerFactory transFactory=TransformerFa
Transformer transformer=transFactory.n
transformer.transform(sour
//Step 4: print out the result
out.println(outHtml.toStri
%>
</body>
</html>
..........................
Hope it helps.