This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: to extract the longest string (fwd)


Hi,

> I want to concatnate the 'align' attributes of the <col> under each 
> <row>  into  separate strings and after that I want to extract the
> lengthiest of the strings.
> 
> For example first <col> attributes gives "ll"
> 	    second <col> attribute gives  "ccc"
> 	    third <col> attribute gives "rrrr"
> 						
> I must get "rrrr" as the output since that is the lengthiest of the
> three string.
> 
> I hope someone will help me with an XSL script.
> 
> <?xml version="1.0"?>
> <table>
> <row>
> 	<col align="l"/>
> 	<col align="l"/>
> </row>
> <row>
> 	<col align="c"/>
> 	<col align="c"/>
> 	<col align="c"/>
> </row>
> <row>
> 	<col align="r"/>
> 	<col align="r"/>
> 	<col align="r"/>
> 	<col align="r"/>
> </row>
> </table>

The following works similar to a solution recently posted by Jeni:

<xsl:template match="table">
   <xsl:for-each select="row">
      <xsl:sort select="count(col)" 
                data-type="number" order="descending" />
      <xsl:if test="position()=1">
         <xsl:for-each select="col">
            <xsl:value-of select="@align" />
         </xsl:for-each>
      </xsl:if>
   </xsl:for-each>
</xsl:template>

Note: it does not exactly what you describe.
It selects the row with the biggest number of cols and then
concatenates all the values of the align attribute.
Since they are all of length 1, the result will be the expected "rrrr".

Regards,
Oliver


/-------------------------------------------------------------------\
|  ob|do        Dipl.Inf. Oliver Becker                             |
|  --+--        E-Mail: obecker@informatik.hu-berlin.de             |
|  op|qo        WWW:    http://www.informatik.hu-berlin.de/~obecker |
\-------------------------------------------------------------------/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]