[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Getting a longest node

Subject: Re: Getting a longest node
From: Sebastian Rahtz <sebastian.rahtz@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 17 Jan 2000 16:27:31 +0000 (GMT)
xsl longest value node sort
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.