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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to