NICE! thanks, Jens!! I like that there is a choice of ";" or "," as field separator. I bet you could add a choice of to quote or not, too.
position() < last()
I think I would use:
position() != last()
The option to use quotes or not is actually in there already:
<!-- if next line is active, strings will be wrapped in `"' -->
<!-- if next line is active, strings will not be wrapped at all -->
<!-- xsl:template name="wrap-strings"><xsl:text></xsl:text></xsl:template -->
Thanks, David! I missed that.
Thank you for this file. You have helped expand my understanding of XSLT greatly.
How do you actually use this file?
copy the XSLT and save to wherever you can find it. make sure the extension is .xsl (not .xsl or .xml)
when Export (as XML) from your database table/layout. when the dialog appears select FMPXMLRESULT and specify the XSLT (that you saved).
Thanks Beverly for that. Extension is .xslt. You might name it 'export.xslt'.
If file 'export.xslt' is in the same folder as your database, the path is 'file:export.xslt'.
I recommend using .xsl for the extension so that it's more apt to be read correctly by other apps.
And if the FM Export is scripted, the path can be any valid path for the platform.
I called it
Thank you again for your great contributions to the FM-XML community!
Sent from miPhone
Hi beverly and JensT (Jens),
A question for my future knowledge.
Is it, (for distribution purposes), possible to store the XSLT-code inside your FileMaker solution, (preferably in a text field), and export it prior to the XML-export?
I only need a yes or no answer and some indication on difficulty level for now, so that I know in advance, if it should come up in the future.
With best regards Magnus Fransson.
Magnus, the export-field-contents (script step) is apt to munge the text if stored in a global TEXT field. If you followed my example XSLT, I recommend that you store the XSLT file in a CONTAINER field, then export when needed with Export Field Contents.
no: as text in a text field
yes: as a document in a container field
This is a very nice way to output headers with CSV data.
thanks for posting your work,
Maybe one could add an xslt to export the xslt as UTF-8?
I would perhaps myself also amend JensT's (Jens') xslt to use variables and and xsl-ifs or something to set each variable options at the top of the document, just for readability and easier modification. I don't know xml as well as you do, but hopefully that could be doable?
If you put your xslt in text field, use UTF-16.
Put it in a container field and you don't need to make the XSLT as UTF-16.
David, I have a way (a FMP database actually) to create an "import" which creates the XSLT to import into FileMaker from other XML sources. It's not fool-proof and some understanding of XPath is still required. I use it to import DDR and other XML.
There is a published XSLT that helps with some of the import and XPath issues:
(also by Jens! thank you!)
And there is a published Export to Excel (with XSLT), see these threads:
https://community.filemaker.com/message/558207 (latest version here)
(thank you Doug!)
But creating XSLT to create XSLT is possible, just don't use Export-Field-Contents to get the encoding correct!
And I would also amend Jens latest example and place the variables at the top. But if it works, why change it?
Lots of good ideas... I'll see what I come up with if and when I need to implement this for a client (or if I just feel like "playing" with it).
Would really like to see this - but I am unable to download the file. Permissions are blocking the download.
You don't have permission to access "http://community.filemaker.com/external-link.jspa?" on this server.
see Flexible CSV export from FileMaker via XSLT | DJT Organisationsberatung
Here is a good example where "your favorite new function (in FMP16)", TextEncode() suddenly made things a lot simpler.
Precisely! that's why I "updated" my article:
(and it points back to the original link, still valuable to read:
Firstly I'd like to say thanks for providing the xslt - It really helped me a lot in getting to understand xslt.
I do have one question though.
I'm trying to export the field names as column headers which is working but I want to ONLY export the field names not the Table name.
I can see you have included a method to cut some of the text out of the coulmn headers but I just can't figure out how to do it.
SO instead of having:Table::Field
I just want the header to be
Can anyone give me a tip on how to acheive this in the xslt?
The other question I have is if it's possible to have completely custom field names?
So instead of using the field names from filemaker we remap them in the xslt
Thanking you in advance
To remove table name, change a template
<xsl:template name="process-column-name"> <xsl:param name="string-to-transform"/> <xsl:choose> <xsl:when test="contains($string-to-transform, '::')"> <xsl:value-of select="substring-after($string-to-transform, '::')"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$string-to-transform"/> </xsl:otherwise> </xsl:choose> </xsl:template>
<xsl:when test="contains($string-to-transform, '::')">
<xsl:value-of select="substring-after($string-to-transform, '::')"/>
To help teach XSLT, I just wrote another blog article on this:
There are several examples and choices.
Thank you so much for your input and assistance.
I've almost got the xslt working the way I need it.
the one issue is that when the resulting .csv is opened in excel there is an additional empty row after each row.
I assume it has something to do with a carriage return but I can't exactly find where that is in the xslt coding. Any suggestions?
If you use Save As (Excel) or Export (Excel), do you get the blank extra line?
What Platform/OS & version of FileMaker & Excel?
It may be an extra CR. What exact method (XSLT) did you use?
Thanks for your response Beverly.
im using the xslt sheet provided by Jen’s above on a windows 10 system.
when exporting to excel, csv, merge file etc the export is fine.
i only get the extra blank lines when I add the code provided by user19752
before inadded the code the export worked fine, but I had table names in the header now I have just the field names but I have a extra blank row after each line that is exported.
OK, let's see if user19752 can shed some light. Perhaps you need to post your final XSLT for review?
I think it is not effect of the change, I got CRCRLF bug on Windows (extra brank lines) also using original xslt.
Only workaround I saw is, use only CR in xslt. This case change two
<xsl:value-of select="' '"/>
(changing line break character of the file to CR have no effect)
But this make result as CR line breaks, can't be used for applications need CRLF.
Retrieving data ...