|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] selecting node with longest data 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








