XML Export to Excel via XSLT - Add Bold Formatting -
i'm generating .xls excel file xml data using xslt file - working , generating valid xls file.
i need extend made of cells bold. here's xml file:
<?xml version="1.0" encoding="utf-8"?> <fmpxmlresult xmlns="http://www.filemaker.com/fmpxmlresult"> <errorcode>0</errorcode> <product build="06-06-2017" name="filemaker" version="proadvanced 16.0.2"/> <metadata> <field emptyok="yes" maxrepeat="1" name="columna" type="text"/> <field emptyok="yes" maxrepeat="1" name="columnb" type="text"/> <field emptyok="yes" maxrepeat="1" name="columnc" type="text"/> <field emptyok="yes" maxrepeat="1" name="columnd" type="text"/> <field emptyok="yes" maxrepeat="1" name="columne" type="text"/> </metadata> <resultset found="6"> <row modid="0" recordid="900"> <col> <data>created: 15-august-2017</data> </col> <col> <data/> </col> <col> <data/> </col> <col> <data/> </col> <col> <data/> </col> </row> <row modid="0" recordid="901"> <col> <data/> </col> <col> <data/> </col> <col> <data/> </col> <col> <data/> </col> <col> <data/> </col> </row> <row modid="1" recordid="902"> <col> <data>name</data> </col> <col> <data>id</data> </col> <col> <data>category</data> </col> <col> <data>number</data> </col> <col> <data>amount</data> </col> </row> <row modid="1" recordid="904"> <col> <data>acme corp pty ltd</data> </col> <col> <data>123456</data> </col> <col> <data>category 1</data> </col> <col> <data>1</data> </col> <col> <data>$456.78</data> </col> </row> <row modid="1" recordid="905"> <col> <data>demo company pty ltd</data> </col> <col> <data>987654</data> </col> <col> <data>category 2</data> </col> <col> <data>1</data> </col> <col> <data>$789.32</data> </col> </row> </resultset> </fmpxmlresult>
i row have bold attribute assigned:
<row modid="1" recordid="902"> <col> <data>name</data> </col> <col> <data>id</data> </col> <col> <data>category</data> </col> <col> <data>number</data> </col> <col> <data>amount</data> </col> </row>
but not sure how in xslt file.
the part of xslt processes rows follows:
<style ss:id="mytitlestyle"> <alignment ss:wraptext="0" /> <font ss:bold="1"/> </style> <xsl:for-each select="fmp:fmpxmlresult/fmp:resultset/fmp:row"> <row> <xsl:for-each select="fmp:col"> <xsl:variable name="i" select="position()" /> <xsl:variable name="zfieldname" select="/fmp:fmpxmlresult/fmp:metadata/fmp:field[$i]/@name" /> <xsl:variable name="zfieldtype" select="/fmp:fmpxmlresult/fmp:metadata/fmp:field[$i]/@type" /> <!-- looping through rows , columns, , can examine cell --> <cell ss:styleid="mytextstyle1"> <data ss:type="string"> <xsl:value-of select="." /> </data> </cell> </xsl:for-each><!-- next column --> </row> </xsl:for-each><!-- next row -->
here's modified for-each. it's not clear how want identify "bold" row. example assumes header row column contains "name"
<?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:fmp="http://www.filemaker.com/fmpxmlresult" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" > <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <xml xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:fmp="http://www.filemaker.com/fmpxmlresult" > <xsl:element name='table'> <xsl:for-each select="//fmp:row"> <row> <!-- if have cell "name", consider header --> <xsl:variable name='header' select='fmp:col[fmp:data="name"]'/> <xsl:for-each select="fmp:col"> <cell> <xsl:if test='$header'> <xsl:attribute name='ss:styleid'>mytextstyle1</xsl:attribute> </xsl:if> <data ss:type="string"> <xsl:value-of select="." /> </data> </cell> </xsl:for-each><!-- next column --> </row> </xsl:for-each><!-- next row --> </xsl:element> </xml> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment