[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Variations in XML to CSV

Subject: Re: Variations in XML to CSV
From: Markus Flatscher <markus.flatscher@xxxxxxxxx>
Date: Thu, 21 Apr 2011 19:17:55 -0400
Re:  Variations in XML to CSV

if you come across this again, David Lee's xmlsh (www.xmlsh.org) might
be worth a look. It comes with a command-line xml2csv command:



On Thu, Apr 21, 2011 at 7:06 PM, Bridger Dyson-Smith
<bdysonsmith@xxxxxxxxx> wrote:
> Hi all,
> thanks for the feedback. I clearly don't know enough about XSLT to use
> it exclusively to solve my problem(s); however, I was able to use some
> simple templates to extract parts of the tree in the right order.
> xml:
> <root>
>  <metadata>
>   <title>Alpha</title>
>   <subject>Sinister</subject>
>   <creator>Beta</creator>
>   <subject>Gamma</subject>
>   <subject>Delta</subject>
>   <subject>Epsilon</subject>
>   <date>2011-04-19</date>
>   <relation>0012_0001</relation>
>  </metadata>
>  <metadata>
>   <title>Zeta</title>
>   <creator>Eta</creator>
>   <creator>Theta</creator>
>   <contributor>Dexter</contributor>
>   <contributor>Iota</contributor>
>   <subject>Kappa</subject>
>   <subject>Lambda</subject>
>   <date>2011-04-19</date>
> <relation>0012_0002</relation>
>  </metadata>
> </root>
> xslt:
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>    exclude-result-prefixes="xs"
>    version="2.0">
>    <xsl:strip-space elements="*"/>
>    <xsl:output method="text"/>
>    <xsl:template match="/">
>        <xsl:apply-templates/>
>    </xsl:template>
>    <xsl:template match="metadata">
>        <xsl:for-each select=".">
>            <xsl:value-of select="normalize-space(title)"
> disable-output-escaping="yes"/><xsl:text>&#x9;<xsl:text>
>        </xsl:for-each>
>    </xsl:template>
> </xsl:stylesheet>
> I took the output, dropped it into vim and did a line-by-line find &
> replace (:%s/\t/\r/g) to columnize the data. I then went back to my
> XSLT and added successive templates (commenting out the earlier
> templates) to pull the remaining data.
> example:
> <xsl:template match="metadata">
>        <xsl:value-of select="normalize-space(relation)"
> disable-output-escaping="yes"/><xsl:text>&#x9;</xsl:text>
>        <xsl:for-each select="subject">
>            <xsl:value-of select="normalize-space(.)"
> disable-output-escaping="yes"/><xsl:text>&#x9;</xsl:text>
>        </xsl:for-each>
>    </xsl:template>
> I had consistent points that I could use (values from relation), so
> again in vim :%s/\t0012_0/\r0012_0/g columnized the values and allowed
> me to import into an OpenOffice document.
> It was, all-in-all, a not very elegant solution but it worked. Thanks
> again for the suggestions and feedback!
> Cheers,
> Bridger

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.