I am trying to make a csv from an xml file of the form:
<?xml version="1.0" encoding="UTF-8"?>
<Envelope>
<Header>
<env:MessageSentDateTime>2012-09-19T09:50:04Z</env:MessageSentDateTime>
<env:MessageSequenceNumber>856432</env:MessageSequenceNumber>
</Header>
<Body>
<Data>
<Data:ID>
<Data:AODB>9346280</Data:AODB>
<Data:Ref>
<common:Code>HJ</common:Code>
<common:num>8113</common:num>
</Data:Ref>
</Data:ID>
... Continues like this, no set number of nodes, parts or AnotherParts
</Body>
Second message starting with <Header> ending with </Body>,
will be more than 2 in practice
</Envelope>
I want to put a newline in the csv file at the /Body tag since this indicates a new message. There will be a mixture of messages so different numbers of nodes, different numbers of parts and no consistent end node in the Body part. In addition, there will be nodes that do not contain any text but I still want a comma there.
So far I have:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*[not(*)]">
<xsl:value-of select="normalize-space(.)"/>
<xsl:text>,</xsl:text>
</xsl:template>
<xsl:template match="Body[last()]">
<xsl:value-of select="normalize-space(.)"/>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
It also adds a comma after the last piece of information in Body. I'd like to replace that comma with a newline, is there a simple way to do this?
Regards, David