Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

Srinivas Rallapalli
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose i have an XML file like the following,
<?xml version="1.0" encoding="UTF-8"?>
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="">
<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(.)"/>
Max string is: <xsl:value-of select="$Length"/>
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.
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!