Results: Do you know how to use XSLT to convert XML to tabulated format ? 

Voters
5 You may not vote on this poll

  • No, dunno.
    60.00%
  • I know how, but I won't tell :-)
    20.00%
  • The XSLT specs are not make for this situation
    0%
  • Use xalan !
    0%
  • Use jato !
    20.00%
    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Posts
    2
    Rep Power
    0

    Question XML to tabbed format (xalan) ?


    I am trying to convert an XML file holding a stock trading history to tabulated format without writing a lot of code.
    The XML file is nested and uses tabulators to give a nice look.

    However, using XSLT with xalan, indent="no", I always end up with tabulators in the output. I believe they are copied from the input by apply-templates.

    Is there a way to avoid this, and to get a file which holds the values separated by tabulators ?

    My two other options right now are using jato (which seems to much, since I only need the data conversion, not the data objects) or writing my own skinny XML parser.

    I look forward to your input.
    Here a little flame to spark replies: Surely it must be possible to produce other formats from XML without much trouble ?

    Both xml and xsl attached.
    (Attached manually since I somehow lost the attachment.)

    ----- histvalues.xsl -----
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xalan="http://xml.apache.org/xslt">

    <xslutput method="xml"
    encoding="UTF-8"
    indent="yes"
    xalan:indent-amount="111"
    version = "1.0"
    omit-xml-declaration = "yes"
    standalone = "no"
    doctype-public = "text/public"
    doctype-system = "text/system"
    cdata-section-elements = ""
    media-type = "text/plain"
    />

    <xsl:template match="/">#<xsl:apply-templates/></xsl:template>

    <xsl:template match="histvalues">[<xsl:apply-templates/>]</xsl:template>

    <xsl:template match="symbol">symbol=<xsl:value-of select="@sym"/>[<xsl:apply-templates/>]</xsl:template>

    <xsl:template match="day">day=<xsl:value-of select="@count"/> <xsl:apply-templates/></xsl:template>

    <xsl:template match="price"> p<xsl:apply-templates/>P</xsl:template>

    <xsl:template match="volume"> <xsl:apply-templates/></xsl:template>

    <xsl:template match="low"> <xsl:apply-templates/></xsl:template>

    <xsl:template match="high"> <xsl:apply-templates/></xsl:template>

    <xsl:template match="kassa"> <xsl:apply-templates/></xsl:template>

    <xsl:template match="closedate"> <xsl:apply-templates/></xsl:template>

    <xsl:template match="clearclosedate"> <xsl:apply-templates/></xsl:template>

    </xsl:stylesheet>

    ----- histvalues.xml -----
    <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
    <?xml-stylesheet href="histvalues.xsl" type="text/xsl" ?>

    <histvalues>

    <symbol sym="SIE.ETR">

    <day count="0"> <price>67.94</price>
    <volume>7057625.0</volume>
    <low>67.72</low>
    <high>69.9</high>
    <kassa>68.16</kassa>
    <closedate>994269929</closedate>
    <clearclosedate>2001-07-04</clearclosedate>

    </day>

    <day count="1">
    <price>64.04</price>
    <volume>6784440.0</volume>
    <low>63.31</low>
    <high>66.9</high>
    <kassa>63.8</kassa>
    <closedate>994356324</closedate>
    <clearclosedate>2001-07-05</clearclosedate>

    </day>


    </symbol>

    </histvalues>
    Last edited by Highlander; July 13th, 2001 at 05:58 AM.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Ireland
    Posts
    10
    Rep Power
    0
    Hey,

    Do you want to produce another XML file or just the info from the XML file with the vlaues in tab format. Sorry but your request seemed a bit fuzzy?

    have you come across JDOM (http://www.jdom.org), its a java package that allows to do do really handy things to xml files. You can create new xml files, but for your needs you can also read existing xml files.

    once you have it read into your java program, you can do whatever it is you want to it!(Still a bit fuzzy on that one )

    Its opensource and easy to use. Thats of course if you know java? Still java is handy as well...

    Hope that helps
    cya
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Posts
    2
    Rep Power
    0

    Thumbs up Xml to non xml tabbed format


    No, I want to produce non-xml tabbed format.

    Right now, I find jato nice to use; I started from the code in the file/directory/tree example. I build my object hierarchy using jato, then produced output using a visitor/descend pattern.

    The fact that dom-based parsers like jato have to build the parse tree before they allow you to process the input seems a bit annoying, that is, forbidding, to a (near-)real-time application processing lots of data. That is the only gripe have with jato.

    Maybe the very basic parser/tokenizer that you get if you use sax or sax2 is really all you need, but it seems a little crude and uninspiring to me. It could need a jato-like wrapper.

IMN logo majestic logo threadwatch logo seochat tools logo