[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: Fri, 11 Feb 2005 09:55:20 -0000
ian vaughan
How could you get the record titles and results to return on a line
below,

so for example instead of being like

UniqueRecordID, RegistrationNumber, RegisteredName, Address1, Address2,
Address3, Address4,PostCode, DateComplete, DescriptionOfWorkItems,
DescriptionOfWorkItems 2,02,Name,Street
Name,,,Town,SA128JW,20/01/2005,Shower,New Unit,2,02,Name,Street
Name,,,Town,SA128JW,20/01/2005,Shower,New Unit

It would be like

UniqueRecordID, RegistrationNumber, RegisteredName, Address1, Address2,
Address3, Address4,PostCode, DateComplete, DescriptionOfWorkItems,
DescriptionOfWorkItems

2,02,Name,Street Name,,,Town,SA128JW,20/01/2005,Shower,New Unit
2,02,Name,Street Name,,,Town,SA128JW,20/01/2005,Shower,New Unit
etc........

Any ideas most appreciated

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

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

> 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

The way to the best solution depends on the XML. When no information is
provided, are the elements then missing or do they have no text node
children?

If I may assume the latter, you might try this:

<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:text>UniqueRecordID, RegistrationNumber, RegisteredName,
Address1, Address2, Address3, Address4,PostCode, DateComplete,
DescriptionOfWorkItems, DescriptionOfWorkItems
	</xsl:text>
	<xsl:apply-templates select="//BuildingRecord"/> </xsl:template>

<xsl:template match="BuildingRecord">
	<xsl:apply-templates select=".//*[not(*)]  | .//apd:*/*"/>
	<xsl:text>
	</xsl:text>
</xsl:template>

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

</xsl:stylesheet>

produces:
UniqueRecordID, RegistrationNumber, RegisteredName, Address1, Address2,
Address3, Address4,PostCode, DateComplete, DescriptionOfWorkItems,
DescriptionOfWorkItems 2,02,Name,Street
Name,,,Town,SA128JW,20/01/2005,Shower,New Unit


the field names are generated automatically here, if you prefer hard
coding them, just omit all templates with mode set to 'label'.


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.