Announcement Announcement Module
Collapse
No announcement yet.
XML / XSLT Help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • XML / XSLT Help

    Hello All,
    I am new to Spring MVC. As part of the requirement we are suppose to use XML / XSL as view technology. Since the document is very limited I started browing this forum and found simple example in the "Web" thread http://forum.springframework.org/sho...stractXsltView

    I copied everything and placed all the files in the right diretory. However I am facing odd problem and I keep getting error saying:
    Code:
    Can't load stylesheet from ServletContext resource [/WEB-INF/xsl/login.xslt] in XSLT view 'login'

    I double checked and made sure that xslt is placed in the right directory.
    My spring-servlet.xml looks like this
    Code:
    	<bean name="/login.htm" class="LoginController" />
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    		<property name="basename" value="views" />
    		<property name="defaultParentView" value="parentView" />
    	</bean>
    and views.properties is placed under WEB-INF/classes directory and it looks like:
    Code:
    login.class=LoginView
    login.stylesheetLocation=/WEB-INF/xsl/login.xslt
    login.root=tsm
    Could some one please help me and tell me what is wrong with my configuration.

    Any help will be much appreciated.

  • #2
    Xml / Xslt

    I am not going far with this!.
    Is there any reason why my XSLT is not loading.?

    I am deploying as war file and the directory structure as follows:
    Code:
    WEB-INF
     |---xsl
            |--login.xslt
     |---lib
           |--all Spring dependencies
     |---classes
            |-- views.properties
             ---log4j.properties
             ---ApplicationResources.properties
    --applicationContext.xml
    --spring-servlet.xml
    My views.properties which is located under WEB-INF/classes
    Code:
    login.class=LoginView
    login.stylesheetLocation=/WEB-INF/xsl/login.xslt
    login.root=tsm
    And login.xslt which is located in WEB-INF/xsl looks like
    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="text/html" omit-xml-declaration="yes"/>
    	<xsl:template match="/">
    		<html>
    			<head><title>Hello!</title></head>
    			<body>
    				<h1>My First Words</h1>
    				<xsl:value-of select="message"/>
    			</body>
    		</html>
    	</xsl:template>
    </xsl:stylesheet>
    Can you guys spot any probelm with any of the above files / contents ?

    Please help.

    Comment


    • #3
      Hello,

      Maybe i can help you. But I donīt see your error .
      can you write your LoginView class?

      Regards

      Comment


      • #4
        Thanks ,

        My LoginView class looks as follows:
        Code:
        public class LoginView extends AbstractXsltView {
        
            public Source createXsltSource(Map model, String root, HttpServletRequest req, HttpServletResponse resp)
                    throws Exception {
                DOMSource domSource = new DOMSource();
        
                Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
                Element rootElement = doc.createElement("tsm");
        
                rootElement.appendChild(doc.createTextNode((String) model.get("message")));
                doc.appendChild(rootElement);
        
                domSource.setNode(doc);
                return domSource;
            }
        
        }
        and the error log is:

        Code:
        org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'login': Initialization of bean failed; nested exception is org.springframework.context.ApplicationContextException: Can't load stylesheet from ServletContext resource [/WEB-INF/xsl/login.xslt] in XSLT view 'login'; nested exception is javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
        	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:452)
        	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250)
        	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
        	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247)
        	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161)
        	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:273)
        	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)
        	at org.springframework.web.servlet.view.ResourceBundleViewResolver.initFactory(ResourceBundleViewResolver.java:212)
        	at org.springframework.web.servlet.view.ResourceBundleViewResolver.loadView(ResourceBundleViewResolver.java:156)
        	at org.springframework.web.servlet.view.AbstractCachingViewResolver.createView(AbstractCachingViewResolver.java:159)
        	at org.springframework.web.servlet.view.AbstractCachingViewResolver.resolveViewName(AbstractCachingViewResolver.java:79)
        	at org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1142)
        	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1086)
        	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:841)
        	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:755)
        	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396)
        	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
        	at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:225)
        	at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:127)
        	at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
        	at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
        	at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3214)
        	at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
        	at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
        	at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:1983)
        	at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1890)
        	at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1344)
        	at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
        	at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
        Caused by: org.springframework.context.ApplicationContextException: Can't load stylesheet from ServletContext resource [/WEB-INF/xsl/login.xslt] in XSLT view 'login'; nested exception is javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
        	at org.springframework.web.servlet.view.xslt.AbstractXsltView.cacheTemplates(AbstractXsltView.java:235)
        	at org.springframework.web.servlet.view.xslt.AbstractXsltView.initApplicationContext(AbstractXsltView.java:223)
        	at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
        	at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:86)
        	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:302)
        	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1081)
        	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:429)
        	... 30 more
        Does this help you to investigate my problem?
        Please let me know.

        Comment


        • #5
          Hello I saw the error.

          It was on the xsl file on the sentence :

          Code:
          <xsl:output method="text/html" omit-xml-declaration="yes"/>
          Must be:


          Code:
          <xsl:output method="html" omit-xml-declaration="yes"/>
          I suggested to use for example the Cooktop application to verified before the xsl files.

          Regards

          Comment

          Working...
          X