Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Possible XML Question

by set_uk (Pilgrim)
on Apr 08, 2003 at 19:25 UTC ( #249045=perlquestion: print w/replies, xml ) Need Help??

set_uk has asked for the wisdom of the Perl Monks concerning the following question:

This may be better asked on an XML site - but I am doing the manipulation in Perl so I'll check here.

Using  XML::Generator::DBI to create XML which is then transformed using  XML::LibXSLT.

I am converting to CSV and I have a number of row entries where some column values are NULL and I still want to output commas.

The XSLT appears to ignore the nodes as I assume being NULL they aren't in the nodeset. Anyone had this issue with converting?

Replies are listed 'Best First'.
Re: Possible XML Question
by grantm (Parson) on Apr 08, 2003 at 23:10 UTC

    Database to XML through XSLT to CSV sounds like a very roundabout way to achieve your ends. If your database does not support exporting directly to a CSV, then you could open one DBI connection to execute your query and open a second one to a file using DBD::CSV then loop through the result set doing inserts on the second connection.

      Its not as bad as it sounds - I am trying to achieve one select executed against the DB and then once I have the result set in XML I want to XSLT that to HTML or CSV depending on the situation. This way it minimises the database activity.
Re: Possible XML Question
by CountZero (Bishop) on Apr 08, 2003 at 21:32 UTC

    If you happen to use mySQL, you can directly output a CSV-file from this database.

    See 6.4.1 SELECT Syntax on the mySQL-docs: The SELECT ... INTO OUTFILE 'file_name' form of SELECT writes the selected rows to a file.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Possible XML Question
by dakkar (Hermit) on Apr 09, 2003 at 16:00 UTC

    As you have discovered, the nodes are not in the document, to distinguish between NULL and empty string.

    As for XSLT, you could always do:

    <xsl:template match="row"> <xsl:value-of select="column1"/>,<xsl:value-of select="column2"/>,<!- +- etc etc --> </xsl:template>

    In this way, non-existant elements will get stringified into the empty string.

    -- 
            dakkar - Mobilis in mobile
    

    Most of my code is tested...

    Perl is strongly typed, it just has very few types (Dan)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://249045]
Approved by dragonchild
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2022-05-16 11:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (63 votes). Check out past polls.

    Notices?