|
Subject: Re: Getting a longest node From: Sebastian Rahtz <sebastian.rahtz@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 17 Jan 2000 16:27:31 +0000 (GMT) |
Wendell Piez writes:
> Does anyone know a way I could define a variable that would contain the
> number of characters in the longest node in a node-set? Let the node set in
> question be //DIV[@type='Chapter']: if I have three, with string lengths
> 88888, 99999, and 111110, I want my variable to be 111110.
I did something like this; put all the values into a RTF,
convert it to a node-set, sort it numerically, and find the
last one. I append my (uncommented) code which attempts to work out
column widths for a table by adding together all the cell lengths in
each column and working out proportions
Sebastian
<xsl:template match="table">
<xsl:variable name="What">
<xsl:value-of select="@id"/>
</xsl:variable>
<record id="{$What}">
<xsl:variable name="cells">
<xsl:for-each select=".//cell">
<xsl:variable name="x"><xsl:number/></xsl:variable>
<cell col="{$x}"><xsl:value-of select="string-length(.)"/></cell>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="total">
<xsl:value-of select="sum(xt:node-set($cells)/cell)"/>
</xsl:variable>
<xsl:for-each select="xt:node-set($cells)/cell">
<xsl:sort select="@col" data-type="number"/>
<xsl:variable name="c" select="@col"/>
<xsl:if test="not(preceding-sibling::cell[$c=@col])">
<xsl:variable name="len">
<xsl:value-of select="sum(following-sibling::cell[$c=@col]) + current()"/>
</xsl:variable>
<xsl:text>
</xsl:text>
<fo:table-column column-number="{@col}" column-align="L" column-width="{$len div $total}" />
</xsl:if>
</xsl:for-each>
<xsl:text>
</xsl:text>
</record>
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Getting a longest node, Wendell Piez | Thread | Re: Getting a longest node, Wendell Piez |
| Re: Iteration in XSL, Eric van der Vlist | Date | RE: sorting and parameters, Kay Michael |
| Month |