|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Getting a longest node
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








