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

Re: document('data.csv') fails; workaround needed

Subject: Re: document('data.csv') fails; workaround needed
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 22 Nov 2001 14:19:06 +0000
csv document
Hi Dan,

> Is there a clever way to import CSV data into the stylesheet? The
> following fails of course:
>
>   <xsl:variable name="csv" select="document('data.csv')"/>
>
> I can't alter the file data.csv but need the data in it for a helper
> lookup function. Thanks in advance.

If data.csv stays the same, then convert it to an XML file using
sed or perl or whatever you fancy, and use that.

If data.csv changes, but doesn't contain any <s or &s, then you could
create a wrapper XML document that accesses it as an external entity -
data.xml:

----
<?xml version="1.0"?>
<!DOCTYPE data [
<!ENTITY data SYSTEM 'data.csv'>
]>
<data>&data;</data>
----

You could then access the data using the document() function, though
you'd have to work through the CSV document using string manipulation
functions in XSLT/XPath, which isn't all that fun.

Alternatively, if you're using an XSLT processor that accepts SAX
events you could write a custom entity resolver that reads in the CSV
document and generates SAX events to make the XSLT processor think
that it's accessed an XML document. That would also allow you take
advantage of the string manipulation support in whatever programming
language you were using, such that the XSLT processor 'sees' the CSV
file as elements.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.