tags:

views:

63

answers:

2

I want to generate an XML file using Perl and XSLT. Is it possible to achieve this by updating the XSLT dynamically by uusing values from a hash?

Or is there any better solution for wirting a simple XML file using Perl?

+2  A: 

The answer is "It depends" but generally "Simple" XML can be printed directly from Perl data structiures using XML::Simple module's XMLOut.

For more complicated use XML::Writer.

You can read more on handling of XML in Perl (including printing it) in Perl and XML O'Reilly book - for examples see Chapter 3 online (XML::Writer part): http://oreilly.com/catalog/perlxml/chapter/ch03.html

Also look at Perl-XML FAQ: http://perl-xml.sourceforge.net/faq/

DVK
+1  A: 

XSLT is not for generating XML, it is merely for transforming XML. There's a comparison of the XML interfaces available to Perl on O'Reily's XML site

Rowland Shaw
A 2001 article. Have things not moved on a bit since then?
David Dorward
Not with the XML standard, so these methods will still generate valid XML - agreed, there may be easier ways if your particular installation has kept up with all the pre-requisite libraries for some of the (arguably) simpler options that have come about since then. The article does use an example of generating XML from a hash, per the OP's request, though
Rowland Shaw