Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Maybe returning a DOMSource() with your model like below:</p> <pre><code>@RequestMapping public String overview(Model model) { model.addAttribute("obj", new DOMSource()); return "list"; } </code></pre> <p>You have <a href="http://forum.springsource.org/showthread.php?64198-XsltView-vs-AbstractXsltView-need-help&amp;p=285253#post285253" rel="nofollow">an example</a> on the <a href="http://forum.springsource.org" rel="nofollow">SpringSource forum</a>. </p> <p>Don't forget SimpleFormController (from the example in my link, is deprecated in Spring 3.0.x, but the logic for implementing the XSL View is the same.</p> <p>You could find some things very usefull in the <a href="http://static.springsource.org/spring/docs/3.1.2.RELEASE/spring-framework-reference/htmlsingle/spring-framework-reference.html#view-xslt" rel="nofollow">official docs</a>. </p> <p>In particular, the sections: <a href="http://static.springsource.org/spring/docs/3.1.2.RELEASE/spring-framework-reference/htmlsingle/spring-framework-reference.html#view-xslt-subclassing" rel="nofollow">17.5.1.3 Convert the model data to XML</a> <a href="http://static.springsource.org/spring/docs/3.1.2.RELEASE/spring-framework-reference/htmlsingle/spring-framework-reference.html#view-xslt-viewdefinitions" rel="nofollow">17.5.1.4. Defining the view properties</a> <a href="http://static.springsource.org/spring/docs/3.1.2.RELEASE/spring-framework-reference/htmlsingle/spring-framework-reference.html#view-xslt-transforming" rel="nofollow">17.5.1.5. Document transformation</a></p> <p>Your controller:</p> <pre><code>package xslt; </code></pre> <p>// imports omitted for brevity</p> <pre><code>public class HomePage extends AbstractXsltView { protected Source createXsltSource(Map model, String rootName, HttpServletRequest request, HttpServletResponse response) throws Exception { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element root = document.createElement(rootName); List words = (List) model.get("wordList"); for (Iterator it = words.iterator(); it.hasNext();) { String nextWord = (String) it.next(); Element wordNode = document.createElement("word"); Text textNode = document.createTextNode(nextWord); wordNode.appendChild(textNode); root.appendChild(wordNode); } return new DOMSource(root); } </code></pre> <p>Your <code>view.properties</code> file:</p> <pre><code>home.(class)=xslt.HomePage home.stylesheetLocation=/WEB-INF/xsl/home.xslt home.root=words </code></pre> <p>Your XSLT stylesheet file:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="html" omit-xml-declaration="yes"/&gt; &lt;xsl:template match="/"&gt; &lt;html&gt; &lt;head&gt;&lt;title&gt;Hello!&lt;/title&gt;&lt;/head&gt; &lt;body&gt; &lt;h1&gt;My First Words&lt;/h1&gt; &lt;xsl:apply-templates/&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;xsl:template match="word"&gt; &lt;xsl:value-of select="."/&gt;&lt;br/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Good luck!</p> <p>Added about the <a href="http://xmlgraphics.apache.org/fop/1.1rc1/servlets.html" rel="nofollow">Apache FOP project and XSL Transformation with Servlets</a>:</p> <pre><code>private FopFactory fopFactory = FopFactory.newInstance(); private TransformerFactory tFactory = TransformerFactory.newInstance(); public void init() throws ServletException { //Optionally customize the FopFactory and TransformerFactory here } [..] //Setup a buffer to obtain the content length ByteArrayOutputStream out = new ByteArrayOutputStream(); //Setup FOP Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out); //Setup Transformer Source xsltSrc = new StreamSource(new File("foo-xml2fo.xsl")); Transformer transformer = tFactory.newTransformer(xsltSrc); //Make sure the XSL transformation's result is piped through to FOP Result res = new SAXResult(fop.getDefaultHandler()); //Setup input Source src = new StreamSource(new File("foo.xml")); //Start the transformation and rendering process transformer.transform(src, res); //Prepare response response.setContentType("application/pdf"); response.setContentLength(out.size()); //Send content to Browser response.getOutputStream().write(out.toByteArray()); response.getOutputStream().flush(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload