How to create CSV/Text form XML

Discussion in 'XML' started by stefan, Apr 1, 2005.

  1. stefan

    stefan Guest

    Hello *,

    i've no expierence with XML and I hope someone can help me out with this.
    Following problem:
    I've an XML File and need just some parts (lines) in the result file. This
    should have CSV/text style.
    In this case I need only lines where dbid="feld2" or dbid="feld4".

    <?xml version="1.0" encoding="UTF-8"?>
    <items title="Execution">
    <item>
    <item_field dbid="feld1" label="Plan: Name" root="106" edit_type="list"
    size="40">Hupe</item_field>
    <item_field dbid="feld2" label="Plan: Date" edit_type="date"
    size="10">15.02.2005</item_field>
    <item_field dbid="feld3" label="Plan: Beschreibung" edit_type="memo"
    size="-1">washtmlonceConnect SUT as modem to PC with Vodafone</item_field>
    <item_field dbid="feld4" label="Plan: Ersteller" root="-1"
    edit_type="list" size="20">Heinz</item_field>
    </item>
    <item>
    <item_field dbid="feld1" label="Plan: Name" root="106" edit_type="list"
    size="40">Honk</item_field>
    <item_field dbid="feld2" label="Plan: Date" edit_type="date"
    size="10">18.02.2005</item_field>
    <item_field dbid="feld3" label="Plan: Beschreibung" edit_type="memo"
    size="-1">washtmlonceSet up call via IrDA using AT commands with
    Vodafone</item_field>
    <item_field dbid="feld4" label="Plan: Ersteller" root="-1"
    edit_type="list" size="20">Heino</item_field>
    </item>
    </items>

    The result should look like this:

    Plan: Date;15.02.2005;Plan: Ersteller;Heinz
    Plan: Date;18.02.2005;Plan: Ersteller;Heino

    I need an XLS file which does the convertion.

    As converter I'm using saxon.


    Thanks Stefan
     
    stefan, Apr 1, 2005
    #1
    1. Advertising

  2. stefan

    Romin Guest

    Here is the XSLT that lets you extract out the elements that you need.
    You can do the formatting accordingly:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="text"/>

    <xsl:template match="/">
    <xsl:for-each select="items/item">
    <xsl:for-each select="item_field[@dbid='feld2' or
    @dbid='feld4']">
    <xsl:value-of select="."/>
    </xsl:for-each>
    </xsl:for-each>
    </xsl:template>

    </xsl:stylesheet>
     
    Romin, Apr 1, 2005
    #2
    1. Advertising

  3. stefan

    stefan Guest

    Romin wrote:

    > Here is the XSLT that lets you extract out the elements that you need.
    > You can do the formatting accordingly:
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > <xsl:eek:utput method="text"/>
    >
    > <xsl:template match="/">
    > <xsl:for-each select="items/item">
    > <xsl:for-each select="item_field[@dbid='feld2' or
    > @dbid='feld4']">
    > <xsl:value-of select="."/>
    > </xsl:for-each>
    > </xsl:for-each>
    > </xsl:template>
    >
    > </xsl:stylesheet>
    >
     
    stefan, Apr 1, 2005
    #3
  4. stefan

    stefan Guest

    Hi Romin,

    thanks for your answer.
    This was quite close to the solution.
    I changed in the following way.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="text"/>

    <xsl:template match="/">
    <xsl:for-each select="items/item">
    <xsl:for-each select="item_field[@dbid='feld2' or @dbid='feld4']">
    <xsl:value-of select="."/>;<xsl:text/>
    </xsl:for-each>
    <xsl:text>
    </xsl:text>
    </xsl:for-each>
    </xsl:template>

    </xsl:stylesheet>


    Could you explain the line:
    <xsl:value-of select="."/>
    What is this for?


    Thanks Stefan

    Romin wrote:

    > Here is the XSLT that lets you extract out the elements that you need.
    > You can do the formatting accordingly:
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > <xsl:eek:utput method="text"/>
    >
    > <xsl:template match="/">
    > <xsl:for-each select="items/item">
    > <xsl:for-each select="item_field[@dbid='feld2' or
    > @dbid='feld4']">
    > <xsl:value-of select="."/>
    > </xsl:for-each>
    > </xsl:for-each>
    > </xsl:template>
    >
    > </xsl:stylesheet>
    >
     
    stefan, Apr 1, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michal Mikolajczyk
    Replies:
    0
    Views:
    666
    Michal Mikolajczyk
    Feb 13, 2004
  2. Skip Montanaro
    Replies:
    0
    Views:
    729
    Skip Montanaro
    Feb 13, 2004
  3. Tintin92
    Replies:
    1
    Views:
    1,729
    Andrew Thompson
    Feb 14, 2007
  4. Sonu
    Replies:
    1
    Views:
    809
  5. jliu66
    Replies:
    0
    Views:
    520
    jliu66
    Oct 19, 2007
Loading...

Share This Page