Reputation: 413
I have a database in Filemaker and I would like to export the table in xml format with this layout:
<?xml version="1.0" encoding="UTF-8"?>
<ricette>
<tipologia>Gelato al Latte</tipologia>
<nome>Fior di Panna</nome>
<ingrediente>BaseBiancaScirocco_2014 no condensato</ingrediente>
<qta>1234</qta>
<ingrediente>Panna Fresca 35%mg</ingrediente>
<qta>1234</qta>
<ingrediente>Latte Intero Fresco AQ</ingrediente>
<qta>1234</qta>
<tipologia>BaseGiallaScirocco</tipologia>
....
....
</ricette>
this is the data table in filemaker:
http://postimg.org/image/hjoparu8b/
I have created this XSL export file:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fm="http://www.filemaker.com/fmpxmlresult"
exclude-result-prefixes="fm">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<!-- expected columns -->
<xsl:variable name="TYPO" select="1" />
<xsl:variable name="NAME" select="2" />
<xsl:variable name="INGREDIENT" select="3" />
<xsl:variable name="QTY" select="4" />
<xsl:template match="/">
<ricette>
<xsl:for-each select="fm:FMPXMLRESULT/fm:RESULTSET/fm:ROW">
<tipologia><xsl:value-of select="fm:COL[$TYPO]/fm:DATA"/></tipologia>
<nome><xsl:value-of select="fm:COL[$NAME]/fm:DATA"/></nome>
<ingrediente><xsl:value-of select="fm:COL[$INGREDIENT]/fm:DATA"/></ingrediente>
<qta><xsl:value-of select="fm:COL[$QTY]/fm:DATA"/></qta>
</xsl:for-each>
</ricette>
</xsl:template>
</xsl:stylesheet>
but the result is:
<?xml version="1.0" encoding="UTF-8"?>
<ricette>
<tipologia>Gelato al Latte</tipologia>
<nome>Fior di Panna</nome>
<ingrediente>BaseBiancaScirocco_2014 no condensato</ingrediente>
<qta>1234</qta>
<tipologia>Gelato al Latte</tipologia>
<nome>Fior di Panna</nome>
<ingrediente>Panna Fresca 35%mg</ingrediente>
<qta>1234</qta>
<tipologia>Gelato al Latte</tipologia>
<nome>Fior di Panna</nome>
<ingrediente>Latte Intero Fresco AQ</ingrediente>
<qta>1234</qta>
...
...
<ricette>
In the result file there is a lot of space from row to row and ther isn't the tab.
Upvotes: 0
Views: 319
Reputation: 117103
In order to have the result indented automatically, start your stylesheet with:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fm="http://www.filemaker.com/fmpxmlresult"
xmlns:xalan="http://xml.apache.org/xalan"
exclude-result-prefixes="fm xalan">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" xalan:indent-amount="4"/>
However, this will not produce the result you show, because your
indenting is not based on the actual hierarchy of the output, where
tipologia
, nome
, ingrediente
and qta
are all siblings of
each other.
In order to get fake indents as shown in your expected output, you would have to disable automatic indenting and insert the required white space as literal text, for example:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fm="http://www.filemaker.com/fmpxmlresult"
exclude-result-prefixes="fm">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
<!-- expected columns -->
<xsl:variable name="TYPO" select="1" />
<xsl:variable name="NAME" select="2" />
<xsl:variable name="INGREDIENT" select="3" />
<xsl:variable name="QTY" select="4" />
<xsl:template match="/">
<ricette>
<xsl:text> </xsl:text>
<xsl:for-each select="fm:FMPXMLRESULT/fm:RESULTSET/fm:ROW">
<xsl:text>	</xsl:text>
<tipologia><xsl:value-of select="fm:COL[$TYPO]/fm:DATA"/></tipologia>
<xsl:text> 		</xsl:text>
<nome><xsl:value-of select="fm:COL[$NAME]/fm:DATA"/></nome>
<xsl:text> 			</xsl:text>
<ingrediente><xsl:value-of select="fm:COL[$INGREDIENT]/fm:DATA"/></ingrediente>
<xsl:text> 				</xsl:text>
<qta><xsl:value-of select="fm:COL[$QTY]/fm:DATA"/></qta>
<xsl:text> </xsl:text>
</xsl:for-each>
</ricette>
</xsl:template>
Note also that in your expected output, there seems to be grouping of ingredients by name - but your stylesheet does not do anything to achieve such grouping.
I am not sure what cause the double returns; I'd suggest you make sure your stylesheet uses only LF or CR as line delimiters, not both. It could also be an artifact created by the application you are using to view the result (esp. if you're on Windows).
Upvotes: 2