Results 1 to 5 of 5

Thread: XSLT transformation (newbie)

  1. #1

    Default XSLT transformation (newbie)

    Hi,

    I have tried to implement my own XSLT based servlet using the Spring documentation (page 142-144). However as a complete Spring newbie (just left Cocoon and Maverick) I am lost.

    Instead of posting long file listings to this forum, I would rather ask if anybody have
    any working example using XSLT transformation (AbstractXsltView) that they want to share with me.

    You may mail the code directly to me.

    Thanks
    peter@easyspeedy.com

  2. #2
    Join Date
    Aug 2004
    Location
    San Jose, CA
    Posts
    24

    Default

    What specific problems are you having? You don't need to post all of your configuration, but snippets of views.properties, applicationContext.xml, and *-servlet.xml would be helpful.

    How are you serialzing your model data into a DOM node? Have you extended AbstractXsltView?

    - Justin Makeig

  3. #3

    Default

    Hi,

    Ok, I think my problem is understanding the relationship between controlers and viewresolvers.

    Have a look at this configuration.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">


    <beans>
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/*.html">ccDefaultExistController</prop>
    </props>
    </property>
    </bean>

    <bean id="ccDefaultExistController" class="com.easyspeedy.spring.ctl.CcDefaultExistCon troller">
    <property name="xquery">
    <value>/WEB-INF/xquery/cp/docs.xq</value>
    </property>
    <property name="extension">
    <value>.xml</value>
    </property>
    <property name="viewName">
    <value>xsltTest</value>
    </property>
    </bean>

    <bean id="xsltTest" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="viewClass">
    <value>com.easyspeedy.spring.web.servlet.view.CcDe faultXsltView</value>
    </property>
    </bean>

    <bean id="myView" class="com.easyspeedy.spring.web.servlet.view.CcDe faultXsltView">
    <property name="stylesheetLocation">
    <value>/WEB-INF/views.properties</value>
    </property>
    </bean>
    </beans>

    views.properties
    xsltTest.class=com.easyspeedy.spring.web.servlet.v iew.CcDefaultXsltView
    xsltTest.stylesheetLocation=/xdfs/stylesheets/empty.xslt

    My controller bean (ccDefaultExistController) fetches data from an xmldb database (exist-db.org) creates a DOM and add the DOM to map model. ModelAndView(getViewName(), model); The view name is "xsltTest".

    I now assume that the "xsltTest" InternalResourceViewResolver bean get hold of the ModelAndView object from the Controller. But how is the resolver identified ?
    Via its bean ID "xsltTest" ?

    Is it correct that the InternalResourceViewResolver calls the "myView" CcDefaultXsltView bean and runs its function createDomNode() ?
    The controller returns w3 dom tree in the map model and this model is being passed on to CcDefaultXsltView.createDomNode().
    The createDomNode() does not do a lot. It just returns the DOM tree.

    2. The views.properties file has "xsltTest.class=com.easyspeedy.spring.web.servlet. view.CcDefaultXsltView"
    Should the "xsltTest." reflect the bean id of the ViewResolver
    or should it reflect the ViewName of the controller ?

    3. I feel that this line is wrong
    xsltTest.class=com.easyspeedy.spring.web.servlet.v iew.CcDefaultXsltView

    Why does CcDefaultXsltView has a entry in the property file pointing to itself ?


    Any help would be appreciated

    Peter

  4. #4
    Join Date
    Aug 2004
    Location
    San Jose, CA
    Posts
    24

    Default

    Peter,
    You've got a lot going on here. I'm not sure I can directly address your questions, but I can provide a simplified example of how I'm resolving XSLT views in my application.

    First, I've got a urlMapping bean just like you've configured below. The mappings point to another bean (presumably a bean, such as a controller, that can handle a request).
    Code:
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="mappings">
    			<props>
    				<prop key="/test.html">myForm</prop>
    				...
    		</props>
    	</property>
    </bean>
    The controller below extends org.springframework.web.servlet.mvc.SimpleFormCont roller. The formView property is just a string that the ViewResolver will use to look up the actual view class.
    Code:
    <bean id="myForm" class="com.thatone.web.MyForm" lazy-init="true">
    	<property name="formView"><value>myForm</value></property>
    	...
    </bean>
    I'm using a ResourceBundleViewResolver in my set-up. It looks for the file views.properties (where the views part is set with the basename property) on the classpath. It uses the view name specified in the controller to look up the corresponding view class that will do the actual rendering of the model. InternalResourceViewResolver, on the other hand, tries to resolve the view from the path that its given. It doesn't use views.properties.

    Code:
    <bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    	<property name="basename">
    		<value>views</value>
    	</property>
    </bean>
    My views.properties looks something like this. The XsltViewImpl class is an extension of AbstractXsltView.
    Code:
    myForm.class=com.thatone.web.XsltViewImpl
    myForm.stylesheetLocation=WEB-INF/xsl/MyForm.xsl
    I hope this helps.

    - Justin Makeig

  5. #5

    Default

    Hi Justin,

    Thanks for your help - I got it working.

Similar Threads

  1. Spring and XSLT
    By EPiXNiCROS in forum Web
    Replies: 4
    Last Post: Aug 27th, 2007, 02:31 PM
  2. Replies: 1
    Last Post: Jun 12th, 2005, 08:46 AM
  3. Replies: 1
    Last Post: Sep 6th, 2004, 12:30 AM
  4. XSLT transformation
    By domkat in forum Web
    Replies: 0
    Last Post: Aug 31st, 2004, 08:39 AM
  5. Replies: 4
    Last Post: Aug 13th, 2004, 12:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •