This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
selecting node with longest data string
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Subject: [xsl] selecting node with longest data string
- From: Mayura Malagala <TS2664 at emirates dot com>
- Date: Sat, 25 Aug 2001 15:16:50 +0400
- Reply-To: xsl-list at lists dot mulberrytech dot com
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