Formatting Text Output with XML

Discussions

XML & Web services: Formatting Text Output with XML

  1. Formatting Text Output with XML (5 messages)

    I'm curious as to whether anyone has used XSL to format a plaintext output. We started using XSL because it appeared to be a versatile technology, but we are quickly realizing it is only good for our HTML output. We need HTML, plaintext, and PDF. PDF generation via XSL is much too slow. And I'm not sure if it would work for plaintext. What we need is formatting (for e-mail bodies) which may include rows and columns that need to be aligned properly. There is no right or left padding in XSL.
    We've already compromised our framework and taken the PDF-generation away from the XSL transformation. Must we do it again for plaintext? The value that XSL brings to the table is seeming less and less...
  2. Formatting Text Output with XML[ Go to top ]

    Jakarta Velocity might be of help to you as far formatting text output goes.
  3. Formatting Text Output with XML[ Go to top ]

    XSL has little value unless you're doing XML-to-XML transformation, IMO.

    Like the previous poster, I'd suggest a template engine. I'd suggest Freemarker rather than Velocity, however. Velocity's one of the rare examples of the jakarta project having a decidedly inferior product.
  4. Formatting Text Output with XML[ Go to top ]

    Have you tried Apache FOP for the PDF? I am using this to produce PDF reports from database data. It has several other outputs included text.

    See http://xml.apache.org/fop/index.html
  5. I believe I've found a formula that works (at least with the JDK 1.4 included XSL stuff).

    Try this:

    XML file:

    <?xml version="1.0" ?>
    <nodes>
      <node1>Node One</node1>
      <node2>Node Two</node2>
      <node3>Node Three</node3>
    </nodes>

    XSL file:

    <?xml version="1.0" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" />
    <xsl:template match="/">
    <xsl:variable name="pad" select="' '" />
    <xsl:variable name="pad-length" select="string-length($pad)" />


         <xsl:value-of select="substring($pad,1,$pad-length - string-length(//node1))"/><xsl:value-of select="//node1" />
         <xsl:value-of select="substring($pad,1,$pad-length - string-length(//node2))"/><xsl:value-of select="//node2" />
         <xsl:value-of select="substring($pad,1,$pad-length - string-length(//node3))"/><xsl:value-of select="//node3" />
         <xsl:text>
         </xsl:text>
    </xsl:template>
    </xsl:stylesheet>

    My output was (with 20 space pad):

                Node One Node Two Node Three
  6. FYI:

    My above message has some truncated whitespace. If you want, post a message w/ your email and I'll send you the actual files.

    Dave.