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

selecting node with longest data string

Subject: selecting node with longest data string
From: Mayura Malagala <TS2664@xxxxxxxxxxxx>
Date: Sat, 25 Aug 2001 15:16:50 +0400
xsl get longest string
Hi All,

I'm using MSXML3 sp1.

I've got an XML that looks like :

<?xml version="1.0" encoding="ISO8859-1"?>
<items>
	<item>dd</item>
	<item>eeeee</item>
	<item>aaa</item>
	<item>ffffffffff</item>
	<item>c</item>
	<item>bbbb</item>
</items>

I want to get the item which has the longest data string as its value.
I managed to do it with the following xsl, but it seems very crude. Could
someone please tell me a more efficient way of doing this.


<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.
0" >
<xsl:output method='html' />

<xsl:template match="/">
	<xsl:variable name="SortedItems" >
		<xsl:call-template name="SortItems" />
	</xsl:variable>
	
	<xsl:variable name="FinalValue">
		<xsl:value-of select="substring-before($SortedItems,'|')" />
	</xsl:variable>
	
	longest = <xsl:value-of select="string-length($FinalValue)" />
	
</xsl:template>


<xsl:template name="SortItems">
	<xsl:for-each select="items/item">
		<xsl:sort select="string-length(.)" data-type="number"
order="descending" />
		<xsl:value-of select="." />|
	</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Thanks in advance,
Mayura

 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.