aspose file tools*
The moose likes XML and Related Technologies and the fly likes finding max string length if more than 2 elements are having same length. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "finding max string length if more than 2 elements are having same length." Watch "finding max string length if more than 2 elements are having same length." New topic
Author

finding max string length if more than 2 elements are having same length.

Srinivas Rallapalli
Greenhorn

Joined: May 20, 2003
Posts: 18
suppose i have an XML file like the following,
<?xml version="1.0" encoding="UTF-8"?>
<registers>
<register>
<name>ramesh</name>
<Bits><start>15</start></Bits>
</register>
<register>
<name>xxxxxxxx</name>
<Bits><start>12</start></Bits>
</register>
<register>
<name>srinivas</name>
<Bits><start>20</start><end>16</end></Bits>
</register>
<register>
<name>rajagopi</name>
<Bits><start>6</start><end>0</end></Bits>
</register>
<register>
<name>rama</name>
<Bits><start>10</start><end>7</end></Bits>
</register>
</registers>
here i have to find maximum string length. if i use the xsl file like the following i am getting the result as srinivas.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl utput method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="Length">
<xsl:for-each select="/employees/emp/name">
<xsl:sort select="string-length(.)" order="descending" data-type="number"/>
<xsl:if test="position() = 1">
<xsl:value-of select="string-length(.)"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
Max string is: <xsl:value-of select="$Length"/>
</xsl:template>
</xsl:stylesheet>
but here we have 3 registers( xxxxxxxx,srinivas,rajagopi) with max string length of 8.
here if i find the range of bits, like, start-end, for xxxxxxxx it is 1, because there is no end, and for srinivas it is 4(20-16) and for rajagopi it is 6(6-0). so in these kind of situations i have to give preference to xxxxxxxx, i.e max string length with range 1.
so if i get 2 or more strings with same string length and with various ranges,
then first
1. i have to get the string with max string length and range is 1.
otherwise
if max string length, strings with range 1 are not there, then
2. i should get the string with max string length and range is max.
for the second condition suppose i have srinivas and rajagopi with ranges 4 and 6, so i have to get rajagopi.
is it possible to get it? how i have to change my xsl file so that i will get this result?
please help me . i am trying for it since 3 days.
thanks,
srini.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: finding max string length if more than 2 elements are having same length.
 
Similar Threads
finding max string length if more than 2 elements are having same length.
XSL 2.0 (looking for ideas)
XSLT Help
Grasping Numbers
XSLT : Grouping Child Nodes...