Simple way to go from xml to simple text format

M

mathieu

Hello,

I have the following xml file:

<Elements>
<Element>
<A>1235</A>
<B>Hello</B>
</Element>
...
</Elements>

I would like to produce a text file containing each Element per line
(xml element being separated let say by a whitespace).

$ cat out.txt
12345 Hello
....

The correct solution would be to use fop and write an xsl document,
right ? Thanks for pointer to 'Hello World' example.

Regards,
Mathieu
 
B

Bjoern Hoehrmann

* mathieu wrote in comp.text.xml:
I have the following xml file:

<Elements>
<Element>
<A>1235</A>
<B>Hello</B>
</Element>
...
</Elements>

I would like to produce a text file containing each Element per line
(xml element being separated let say by a whitespace).

$ cat out.txt
12345 Hello
...

The correct solution would be to use fop and write an xsl document,
right ? Thanks for pointer to 'Hello World' example.

XSLT would probably be a simple solution, yes. Note though that Apache
FOP is a XSL Formatting Objects Processor, it's useful if you want to
make complex graphical layouts, not for plain text. For XSLT tutorials,
try a search engine of your choice.
 
M

mathieu

Bjoern said:
* mathieu wrote in comp.text.xml:

XSLT would probably be a simple solution, yes. Note though that Apache
FOP is a XSL Formatting Objects Processor, it's useful if you want to
make complex graphical layouts, not for plain text. For XSLT tutorials,
try a search engine of your choice.

Thanks Björn this is really helpful. Unfortunately there is very
little help on the web when it come to outputing text file. So far I
have (*). But the command using fop does not output anything:

$ fop -xml dummy.xml -xsl dummy.xsl -txt out.txt

Thanks again !
Mathieu

(*)
$ cat dummy.xsl

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="Elements/Element">
<xsl:value-of select="//A"/>
<xsl:text>
</xsl:text><!--produce a newline -->
<xsl:value-of select="//B"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

$ cat dummy.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="dummy.xsl"?>
<Elements>
<Element>
<A>1235</A>
<B>Hello</B>
</Element>
<Element>
<A>4567</A>
<B>World</B>
</Element>
</Elements>
 
M

mathieu

mathieu said:
Thanks Björn this is really helpful. Unfortunately there is very
little help on the web when it come to outputing text file. So far I
have (*). But the command using fop does not output anything:

$ fop -xml dummy.xml -xsl dummy.xsl -txt out.txt

Nevermind xsltproc worked out of the box, I'll use this tool instead.

$ xsltproc dummy.xsl dummy.xml

Sorry for the noise,
Mathieu
 

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

No members online now.

Forum statistics

Threads
474,007
Messages
2,570,266
Members
46,865
Latest member
AveryHamme

Latest Threads

Top