[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]
Subject: Aligning numbers in table cells with xsl
I have an xpath _expression_ in a customisation which is trying to
achieve the following: In a CALS table I have a mixture of columns with text and a column with numbers. I've created a tabstyle 'numbers' (and also 'numberstripe') that should set, only for cells containing a number, a text align of 'right' and an indent (set as a percentage of cell width from the right margin). If a cell contains a text string, then it should not set a right margin or indent. I have had the following coding working in a previous document, but in another document it sets all text and numbers with a text-align of 'right' and a margin-right equal to a user setting (e.g. 40% of cell width). It is a complicated xpath _expression_ to select only the cells contained within <tbody> (i.e. doesn't apply to cells in thead) and only if a cell contains a number. I don't know much about xpath and less about whether the string selection is correct. The XML is: <table frame="all" label="2" tabstyle="numbers"> <title>Mining and manufacturing water use in high and medium water development SWMAs </title> <tgroup cols="4"> <colspec colname="c1" colnum="1" colwidth="1.0*"/> <colspec colname="c2" colnum="2" colwidth="1.0*"/> <colspec colname="c3" colnum="3" colwidth="1.0*"/> <colspec colname="c4" colnum="4" colwidth="1.0*"/> <thead> <row> <entry align="center" valign="bottom">Drainage division</entry> <entry align="center" valign="bottom">SWMA</entry> <entry align="center" valign="bottom">Water use by mining and manufacturing (%)</entry> <entry align="center" valign="bottom">Main commodities mined</entry> </row> </thead> <tbody> <row> <entry morerows="3">North-East Coast</entry> <entry valign="bottom">Barron River</entry> <entry valign="bottom">10</entry> <entry valign="bottom">Metals</entry> </row> <row> <entry valign="bottom">Burdekin River</entry> <entry valign="bottom">1</entry> <entry valign="bottom">Coal</entry> </row> <row> <entry valign="bottom">Fitzroy River</entry> <entry valign="bottom">6</entry> <entry valign="bottom">Coal</entry> </row> <row> <entry valign="bottom">Brisbane River</entry> <entry valign="bottom">1</entry> <entry valign="bottom">Coal</entry> </row> <row> <entry morerows="9">Murray–Darling Basin</entry> <entry valign="bottom">Condamine–Culgoa rivers</entry> <entry valign="bottom"><1</entry> <entry valign="bottom">Coal</entry> </row> <row> <entry valign="bottom">Border Rivers</entry> <entry valign="bottom">2</entry> <entry valign="bottom">Coal</entry> </row> <row> <entry valign="bottom">Gwydir River</entry> <entry valign="bottom">2</entry> <entry valign="bottom">Coal</entry> </row> <row> <entry valign="bottom">Namoi River</entry> <entry valign="bottom">2</entry> <entry valign="bottom">Coal</entry> </row> <row> <entry valign="bottom">Lachlan River</entry> <entry valign="bottom">4</entry> <entry valign="bottom">Metals</entry> </row> <row> <entry valign="bottom">Murrumbidgee River</entry> <entry valign="bottom"><1</entry> <entry valign="bottom">Metals</entry> </row> <row> <entry valign="bottom">Loddon River</entry> <entry valign="bottom"><1</entry> <entry valign="bottom">Gold</entry> </row> <row> <entry valign="bottom">Campaspe River</entry> <entry valign="bottom"><1</entry> <entry valign="bottom">Gold</entry> </row> <row> <entry valign="bottom">Avoca River</entry> <entry valign="bottom">1</entry> <entry valign="bottom">Gold</entry> </row> <row> <entry valign="bottom">Wimmera–Avon rivers</entry> <entry valign="bottom">1</entry> <entry valign="bottom">Mineral sands</entry> </row> <row> <entry morerows="3">South East Coast</entry> <entry valign="bottom">Hunter River</entry> <entry valign="bottom">12</entry> <entry valign="bottom">Coal</entry> </row> <row> <entry valign="bottom">Macquarie–Tuggerah lakes</entry> <entry valign="bottom">6</entry> <entry valign="bottom">Coal</entry> </row> <row> <entry valign="bottom">Hawkesbury River</entry> <entry valign="bottom">4</entry> <entry valign="bottom">Coal</entry> </row> <row> <entry valign="bottom">Latrobe River</entry> <entry valign="bottom">25</entry> <entry valign="bottom">Coal</entry> </row> <row> <entry morerows="2">South-West Coast</entry> <entry valign="bottom">Busselton Coast, Preston River</entry> <entry valign="bottom">3</entry> <entry valign="bottom">Mineral sands</entry> </row> <row> <entry valign="bottom">Collie River</entry> <entry valign="bottom">3</entry> <entry valign="bottom">Coal</entry> </row> <row> <entry valign="bottom">Murray River</entry> <entry valign="bottom">13</entry> <entry valign="bottom">Bauxite, gold, copper, mineral sands</entry> </row> <row> <entry morerows="3">Others</entry> <entry valign="bottom">Ord (WA)</entry> <entry valign="bottom">15</entry> <entry valign="bottom">Gold, diamonds</entry> </row> <row> <entry valign="bottom">Port Hedland (WA)[1]</entry> <entry valign="bottom">47</entry> <entry valign="bottom">Iron ore</entry> </row> <row> <entry valign="bottom">Onkaparinga River (SA)</entry> <entry valign="bottom">1</entry> <entry valign="bottom">Metals</entry> </row> <row> <entry valign="bottom">Torrens River (SA)</entry> <entry valign="bottom">1</entry> <entry valign="bottom">Metals</entry> </row> </tbody> </tgroup> </table> And the customisation: <xsl:template name="table.cell.block.properties"> <xsl:if test="ancestor::d:thead"> <xsl:attribute name="font-weight"> <xsl:value-of select="$tablehdrfontweight"/> </xsl:attribute> <xsl:attribute name="color"> <xsl:value-of select="$tablehdrfontcolour"/> </xsl:attribute> <xsl:attribute name="font-size"> <xsl:value-of select="$tablehdrfontsize"></xsl:value-of><xsl:text>pt</xsl:text> </xsl:attribute> <xsl:attribute name="font-style"> <xsl:value-of select="$tablehdrfontstyle"/> </xsl:attribute> </xsl:if> <!--If table has numbers in the cells, set right-align for text and indent from right-hand margin to centre the numbers--> <!--margin and indent for portrait format tables--> <xsl:if test="(ancestor-or-self::d:table/@tabstyle = 'numbers' or ancestor-or-self::d:table/@tabstyle = 'numberstripe') and not(ancestor::d:thead or ancestor::d:tfoot) and preceding-sibling::d:entry and string(number(.))"> <xsl:attribute name="text-align">right</xsl:attribute> <xsl:attribute name="margin-right"> <xsl:choose> <xsl:when test="self::d:entry/d:footnote"> <xsl:value-of select="$cellfootnoteindent"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$cellnumberindent"/> </xsl:otherwise> </xsl:choose> <xsl:text>%</xsl:text> </xsl:attribute> </xsl:if> </xsl:template> Thanks. --
Dave Gardiner |
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]