How to create CSV/Text form XML

S

stefan

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
 
R

Romin

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>
 
S

stefan

Romin said:
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>
 
S

stefan

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top