Subject: Re: [xsl] RE: XSL-FO and Z-index From: Jesper Tverskov <jesper.tverskov@xxxxxxxxx> Date: Fri, 21 Sep 2012 09:36:19 +0200 |
Thanks for help and suggestions. I have improved my "solution" with this one liner, replacing 13 lines of code: <xsl:variable name="seq-of-character-counts" select="for $i in $seq-of-words[position()] return concat(string-length($i), ' ')" as="item()+"/> Below I bring the improved solution at the moment just made as a stylesheet that returns line count for easy testing. I still have my doubts if it could be implemented in a way that would work also in border cases. But the alternative background image hack, has the problem that it is not easy to fine tune the table layout in a configuration file (for many tables in one go), you must also make a new image. The second alternative of hiding the last rows of the table under the following container, which Ken helped me with, is attractive, but at the moment I have it only working, if the following container is the footer of the page. There is a another table before that footer, that is the last handful of table rows in our table must hide under that other table, and I have the feeling that in order to do that I need to use Z-index, which as far as I know (?) is not yet supported in Apache FOP, at least I don't have it working yet. Cheers Jesper Tverskov http://www.xmlplease.com improved solution: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:output indent="yes"/> <xsl:template name="start"> <xsl:variable name="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</xsl:variable> <xsl:variable name="number-of-lines"> <xsl:call-template name="create-sequence-of-character-counts"> <xsl:with-param name="text" select="$text"/> <xsl:with-param name="maxLineLength" select="80"/> </xsl:call-template> </xsl:variable> <!-- Output --> <xsl:value-of select="$number-of-lines"/> </xsl:template> <xsl:template name="create-sequence-of-character-counts"> <xsl:param name="text"/> <xsl:param name="maxLineLength"/> <xsl:variable name="seq-of-words" select="tokenize(normalize-space($text), ' ')"/> <!-- string-length of spaces + 1 = number of items --> <xsl:variable name="number-of-items" select="string-length(replace(normalize-space($text), '\S', '')) + 1"/> <xsl:variable name="seq-of-character-counts" select="for $i in $seq-of-words[position()] return concat(string-length($i), ' ')" as="item()+"/> <!-- Needed to prevent recursion from spinning out of control --> <xsl:for-each select="$seq-of-character-counts[position()]"> <xsl:if test="$maxLineLength le xs:integer(.)"> <xsl:message terminate="yes" select="'One or more words are longer than maxLineLength'"/> </xsl:if> </xsl:for-each> <xsl:call-template name="seqCounts2lines"> <xsl:with-param name="seqCounts" select="$seq-of-character-counts" as="item()+"/> <xsl:with-param name="number-of-items" select="$number-of-items"/> <xsl:with-param name="maxLineLength" select="$maxLineLength"/> </xsl:call-template> </xsl:template> <xsl:template name="seqCounts2lines"> <xsl:param name="seqCounts"/> <xsl:param name="number-of-items" as="xs:integer"/> <xsl:param name="itemSum" select="0" as="xs:integer"/> <xsl:param name="nextItem" select="1" as="xs:integer"/> <xsl:param name="lines" select="1" as="xs:integer"/> <xsl:param name="maxLineLength"/> <xsl:choose> <xsl:when test="$nextItem le ($number-of-items)"> <xsl:choose> <xsl:when test="$itemSum + xs:integer(subsequence($seqCounts, $nextItem, 1)) lt $maxLineLength"> <xsl:call-template name="seqCounts2lines"> <xsl:with-param name="itemSum" select="$itemSum + xs:integer(subsequence($seqCounts, $nextItem, 1))"/> <xsl:with-param name="nextItem" select="$nextItem + 1" as="xs:integer"/> <xsl:with-param name="seqCounts" select="$seqCounts" as="item()+"/> <xsl:with-param name="number-of-items" select="$number-of-items"/> <xsl:with-param name="lines" select="$lines" as="xs:integer"/> <xsl:with-param name="maxLineLength" select="$maxLineLength"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template name="seqCounts2lines"> <xsl:with-param name="itemSum" select="0"/> <xsl:with-param name="nextItem" select="$nextItem" as="xs:integer"/> <xsl:with-param name="seqCounts" select="$seqCounts" as="item()+"/> <xsl:with-param name="number-of-items" select="$number-of-items"/> <xsl:with-param name="lines" select="$lines + 1" as="xs:integer"/> <xsl:with-param name="maxLineLength" select="$maxLineLength"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:value-of select="$lines"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] RE: XSL-FO and Z-index, Liam R E Quin | Thread | Re: [xsl] RE: XSL-FO and Z-index, G. Ken Holman |
Re: [xsl] RE: XSL-FO and Z-index, Liam R E Quin | Date | Re: [xsl] Using barcode markup in S, Florent Georges |
Month |