You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Peng, Meimin" <mp...@atxna.com> on 2003/12/12 18:18:22 UTC

RE: Struts and XSLT - solved

Hello, 

I did the very similar approach which is I load the resource bundle in the
first beginning and put parameters in hashtable for future used. 
But, when it comes out the struts way, it becomes very mess. If I could find
a better way to change it, I'll do it.

This is a possible solution for internationalized contents. I've been try a
simple app yesterday and it seems work very well.
http://www-106.ibm.com/developerworks/library/wa-xslt/
So, check it out and wish you all have best code.
--Zoe

-----Original Message-----
From: matsuhashi@quick.co.jp [mailto:matsuhashi@quick.co.jp]
Sent: Thursday, December 11, 2003 9:18 PM
To: Struts Users Mailing List
Cc: struts-user@jakarta.apache.org
Subject: Re: Struts and XSLT



Peng Meimin wrote:
>I got a question with working structs and xslt together.


I thought about, in case, how I would approach to a problem as yours. Just
my idea. I will....

(1) transform Properties files into XML format in the deployment time.

Develop a utility class which transformes any Properties files("key=value"
pairs) into well-formed XML format. For example

    ---------------------------
    greeting = こんにちは
    ---------------------------

will be transformed into

    ---------------------------
    <messages>
        <pair>
            <key>greeting</key>
            <value>こんにちは</value>
        </pair>
        <pair>
            ....
        </pair>
        ....
    </messages>
    ---------------------------

Then I will transform all of Application Resource files into
ApplicationResource_??.xml files. Transformation would be done in the
deployment time within a Ant build process. In fact, I have developed an
Ant task for me which does this sort of NON-XML to XML conversion task.

By converting the format, the information becomes accessible for a XSLT
stylesheet via call of
    <xsl:variable name="messages" select="document( ... )"/>.





(2) forward to XSLTServlet, not to JSP

Develop a HttpServlet class which drives XSLT processor. It will read the
xml documents as Source, writes the transformation Result into the
Servlet's OutputStream. The Saxon distribution includes a good sample of a
Servlet class which drives XSLT processor via JAXP API.

An important point is that the XSLT stylesheet will obtain message
resources by

    <xsl:variable name="messages" select="document
('my:://ApplicationResource')"/>

Here I need a magic!.

I want this call to make a XSLT variable stuffed with message key and
message string pairs read from one of the ApplicationResource_??.xml files.

Firstly, how can I can identify which one of the ApplicationResource_??.xml
files to refer? ---- I can identify the locale of the client by looking at
org.apache.struts.action.Action.LOCALE_KEY.

Secondly, I want the XSLT processor to be able to resolve my special URI
string "my:://ApplicationResource". For this, I  have to develop a class
which implements javax.xml.transform.URIResolver interface. This special
URIResolver class will identify the message resource according to the
Action.LOCALE_KEY of the client and return an object of
javax.xml.transform.Souce.

I would definitely maintein a singleton cache of XML-ised
ApplicationResources in the XSLTServlet for better performace.

Why I do not use JSP with JSTL's <x:transform> tag? ----- My solution above
need to be able to invoke
     javax.transofrm.TransformerFactory.setURIResolver(URIResolver
resover) method.
I do not think JSTL provides features which allows you to do such minute
operation to the Transformer object.




I am afraid I may not understand your problem correctly. Hope it helps you.


MATSUHASHI,kazuaki
Japan



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org

CONFIDENTIALITY NOTICE:  The information in this e-mail is privileged and
confidential.  Any use, copying or dissemination of any portion of this
e-mail by or to anyone other than the intended recipient(s) is unauthorized.
If you have received this e-mail in error, please reply to sender and delete
it from your system immediately.

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org