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

RE: Generating a CSV file using XSLT

Subject: RE: Generating a CSV file using XSLT
From: "Ian Vaughan" <i.vaughan@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 9 Feb 2005 13:45:37 -0000
ian vaughan
Any idea of how I could transform the XML doc into the following layout
below in the csv file ??

With the SchemeName at the start of the .csv file then the column titles
followed by the relevant rows of information from the xml doc.


Ie.

SchemeName - DATA

UniqueRecordID  RegistrationNumber  RegisteredName Address1, Address2,
Address3, Address4,PostCode,DateComplete,DescriptionOfWorkItems...
2,02,Name,StreetName, , ,Town,SA128JW,20/01/2005,Shower,New Unit
3,03,Name,StreetName,Road , ,Town,SA128JW,20/01/2005,Shower,New Unit

2,02,NameStreet Name Town SA128JW ,20/01/2005,Shower,New Unit

-----------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:apd="http://www.govtalk.gov.uk/people/AddressAndPersonalDetails">

<xsl:template match="/">
	<xsl:apply-templates select="//BuildingRecord"/> </xsl:template>

<xsl:template match="BuildingRecord">
	<xsl:apply-templates select=".//text()"/>
	<xsl:text>
	</xsl:text>
</xsl:template>

<xsl:template match="text()">
	<xsl:if test="position() &gt; 1
"><xsl:text>,</xsl:text></xsl:if>
	<xsl:value-of select="normalize-space(.)"/> </xsl:template>

<xsl:template match="apd:*//text()">
	<xsl:value-of select="normalize-space(.)"/><xsl:text>
</xsl:text> </xsl:template>

</xsl:stylesheet>

------------------------------



-----Original Message-----
From: Joris Gillis [mailto:roac@xxxxxxxxxx]
Sent: 09 February 2005 11:29
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Generating a CSV file using XSLT

Tempore 12:10:20, die 02/09/2005 AD, hinc in
xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Ian Vaughan
<i.vaughan@xxxxxxxxxxxxxxxxxxxxxxx>:

> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>  version="1.0">
> <xsl:output method="text"/>
> <xsl:template match="BuildingRecord">
> <xsl:value-of
> select="normalize-space(SchemeUniqueRecordIdentifier)"/>,
> <xsl:value-of
> select="normalize-space(CompetentPerson/PersonRegistrationNumber)"/>,
> <xsl:value-of
> select="normalize-space(CompetentPerson/InstallerRegisteredName)"/>,
> <xsl:value-of
> select="normalize-space(WorkPerformed/PropertyInformation/PropertyLoca
> ti
> on/PropertyAddress/)"/>,
> <xsl:value-of
> select="normalize-space(WorkPerformed/DateWorkCompleted)"/>,
> <xsl:value-of
> select="normalize-space(WorkPerformed/DescriptionOfWorkItem)"/>,
> </xsl:template>
> </xsl:stylesheet>
Hi,

Maybe you could make more use of templates to get the same result:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:apd="http://www.govtalk.gov.uk/people/AddressAndPersonalDetails">

<xsl:template match="/">
	<xsl:apply-templates select="//BuildingRecord"/> </xsl:template>

<xsl:template match="BuildingRecord">
	<xsl:apply-templates select=".//text()"/>
	<xsl:text>
	</xsl:text>
</xsl:template>

<xsl:template match="text()">
	<xsl:if test="position() &gt; 1
"><xsl:text>,</xsl:text></xsl:if>
	<xsl:value-of select="normalize-space(.)"/> </xsl:template>

<xsl:template match="apd:*//text()">
	<xsl:value-of select="normalize-space(.)"/><xsl:text>
</xsl:text> </xsl:template>

</xsl:stylesheet>


output:

2,02,NameStreet Name Town SA128JW ,20/01/2005,Shower,New Unit



regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
"Et ipsa scientia potestas est"  - Francis Bacon , Meditationes sacrae

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.