SPFE Documentation | Collections > SPFE Function Reference > index-of-shortest-string

Function: index-of-shortest-string

index-of-shortest-string(strings as xs:string*, current as xs:integer, length-of-shortest as xs:integer, index-of-shortest as xs:integer) as xs:integer

Description

The index-of-shortest-string function returns the index of the shortest string in a sequence of strings. To get the index of the longest string, use index-of-longest-string.

For XSLT geeks: index-of-shortest-string is a recursive polymorphic function. There is a version with one parameter, strings, that is the one you call from your code, and a version with four parameters, that is called by the first version, and which calls itself recursively, to do the work. It is unlikely you will ever want to call the second version yourself.

Return value

Return type: xs:integer

The index of the shortest string.

Source file

$SPFEOT_HOME/1.0/scripts/common/utility-functions.xsl

Parameters

strings

Type: xs:string*

A sequence of strings.

current

Type: xs:integer

The index of the string currently being measured. You should not generally use this parameter in your code. It is used internally by the recursive function calls.

length-of-shortest

Type: xs:integer

The length of the shortest string seen so far as the function is called recursively. You should not generally use this parameter in your code.

index-of-shortest

Type: xs:integer

The index of the shortest string seen so far as the function is called recursively. You should not generally use this parameter in your code.

Definition

            <xsl:function name="sf:index-of-shortest-string" as="xs:integer">
		               <xsl:param name="strings" as="xs:string*"/>
		               <xsl:value-of select="sf:index-of-shortest-string($strings,2,string-length($strings[1]),1)"/>
	           </xsl:function>
         
            <xsl:function name="sf:index-of-shortest-string" as="xs:integer">
		               <xsl:param name="strings" as="xs:string*"/>
		               <xsl:param name="current" as="xs:integer"/>
		               <xsl:param name="length-of-shortest" as="xs:integer"/>
		               <xsl:param name="index-of-shortest" as="xs:integer"/>
		               <xsl:choose >
			                   <xsl:when test="$current le count($strings)">
				                       <xsl:variable name="length-of-current" select="string-length($strings[$current])"/>
				                       <xsl:value-of select="sf:index-of-shortest-string(      $strings,       $current + 1,       min(($length-of-current,$length-of-shortest)),      if ($length-of-current lt $length-of-shortest) then $current else $index-of-shortest)"/>
			                   </xsl:when>
			                   <xsl:otherwise >
				                       <xsl:value-of select="$index-of-shortest"/>
			                   </xsl:otherwise>
		               </xsl:choose>
	           </xsl:function>