L
loc
I'm trying to convert an xml file into CSV using xsltproc.
#file.xml
<?xml-version ="1.0"standalone="no"?>
<NAXML-POSJournal version="3.3">
<TransmissionHeader>
<StoreLocationID>207</StoreLocationID>
</TransmissionHeader>
<JournalReport>
<JournalHeader>
<ReportSequenceNumber>74</ReportSequenceNumber>
<PrimaryReportPeriod>2</PrimaryReportPeriod>
<SecondaryReportPeriod>1</SecondaryReportPeriod>
<BeginDate>2010-02-11</BeginDate>
<BeginTime>03:58:42</BeginTime>
<EndDate>2100-01-01</EndDate>
<EndTime>00:00:00</EndTime>
</JournalHeader>
<SaleEvent>
<BusinessDate>2010-02-11</BusinessDate>
<TransactionDetailGroup>
<TransactionLine status="normal">
<ItemLine>
<ItemCode>
<POSCodeFormat format="upcA"></POSCodeFormat>
<POSCode>028400079037</POSCode>
<POSCodeModifier name="pc">1</POSCodeModifier>
</ItemCode>
</ItemLine>
</TransactionLine>
<TransactionLine status="normal">
<ItemLine>
<ItemCode>
<POSCodeFormat format="upcA"></POSCodeFormat>
<POSCode>049000051148</POSCode>
<POSCodeModifier name="pc">1</POSCodeModifier>
</ItemCode>
</ItemLine>
</TransactionLine>
</TransactionDetailGroup>
</SaleEvent>
</JournalReport>
</NAXML-POSJournal>
Here is the stylesheet:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput method="text"/>
<xsl:template match="NAXML-POSJournal/JournalReport/SaleEvent/
TransactionDetailGroup">
<xsl:for-each select="*">
<xsl:value-of select="."/>
<xsl:text>,</xsl:text>
<xsl:if test="not(position() = last())">
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The output I'm looking for is the values for the following:
<StoreLocationID>,<BusinessDate>,<POSCodeFormat>,<POSCode>
I'd like to get a new line with that info for each <TransactionLine>
How can I make this work?
#file.xml
<?xml-version ="1.0"standalone="no"?>
<NAXML-POSJournal version="3.3">
<TransmissionHeader>
<StoreLocationID>207</StoreLocationID>
</TransmissionHeader>
<JournalReport>
<JournalHeader>
<ReportSequenceNumber>74</ReportSequenceNumber>
<PrimaryReportPeriod>2</PrimaryReportPeriod>
<SecondaryReportPeriod>1</SecondaryReportPeriod>
<BeginDate>2010-02-11</BeginDate>
<BeginTime>03:58:42</BeginTime>
<EndDate>2100-01-01</EndDate>
<EndTime>00:00:00</EndTime>
</JournalHeader>
<SaleEvent>
<BusinessDate>2010-02-11</BusinessDate>
<TransactionDetailGroup>
<TransactionLine status="normal">
<ItemLine>
<ItemCode>
<POSCodeFormat format="upcA"></POSCodeFormat>
<POSCode>028400079037</POSCode>
<POSCodeModifier name="pc">1</POSCodeModifier>
</ItemCode>
</ItemLine>
</TransactionLine>
<TransactionLine status="normal">
<ItemLine>
<ItemCode>
<POSCodeFormat format="upcA"></POSCodeFormat>
<POSCode>049000051148</POSCode>
<POSCodeModifier name="pc">1</POSCodeModifier>
</ItemCode>
</ItemLine>
</TransactionLine>
</TransactionDetailGroup>
</SaleEvent>
</JournalReport>
</NAXML-POSJournal>
Here is the stylesheet:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput method="text"/>
<xsl:template match="NAXML-POSJournal/JournalReport/SaleEvent/
TransactionDetailGroup">
<xsl:for-each select="*">
<xsl:value-of select="."/>
<xsl:text>,</xsl:text>
<xsl:if test="not(position() = last())">
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The output I'm looking for is the values for the following:
<StoreLocationID>,<BusinessDate>,<POSCodeFormat>,<POSCode>
I'd like to get a new line with that info for each <TransactionLine>
How can I make this work?