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

RE: getting the longest text node

Subject: RE: getting the longest text node
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Thu, 3 Apr 2003 10:10:17 -0600
longest text string
florian wrote:
> 
> right now i do it via:
> 
> <xsl:for-each select="/*/*">
>   <xsl:for-each select="/*/*[local-name = local-name(current())]">
> 
> ...
> 
> wrong?

It's a good start, but you'll get each element processed N times,
where N is the number of that elements with that name.  In other
words, if you have two <apple> elements, you'll get each of them
processed twice.

In other words, this is a classic grouping problem... find the
members of a group but eliminate duplicate processing.
Look at http://www.dpawson.co.uk/xsl/sect2/N4486.html for help,
or read ch. 10 of Tennison's "Beginning XSLT".

Lars

> 
> 
> > hi!
> > 
> > how could i access the nodes though, if all i know is their 
> structure
> > but 'foo', 'orange' and 'apple' could be also any other name.. and
> > foo could also contain a flexible amount of children..
> > 
> > all i could think off is some kinda akward looking looping.. : /
> > 
> > ciao!
> > florian
> > 
> > 
> > > I just thought I'd provide a variation.  I can't make any 
> performance 
> > > claims vs. a sort in a for-each. Maybe someone else knows.
> > > 
> > > <xsl:template match="/">
> > >    <xsl:apply-templates select="//orange">
> > >     <xsl:sort data-type="number" order="descending" 
> select="string-length(.)"/>
> > >    </xsl:apply-templates>
> > > </xsl:template>
> > > 
> > > <xsl:template match="orange">
> > >   <xsl:if test="position()=1">
> > >   <LongString type="{name()}" string-length="{string-length(.)}">
> > >    <xsl:value-of select="."/>
> > >   </LongString>
> > > </xsl:if>
> > > </xsl:template>
> > > 
> > > -rick
> > > 
> > > At 10:35 PM 3/11/03 +0100, you wrote:
> > > 
> > > >hi!
> > > >
> > > >i have a xml document like this:
> > > >
> > > >
> > > ><root>
> > > >   <foo>
> > > >     <apple>a</apple>
> > > >     <orange>oiasd</orange>
> > > >   </foo>
> > > >   <foo>
> > > >     <apple>hellooooo</apple>
> > > >     <orange>test</orange>
> > > >   </foo>
> > > ></root>
> > > >
> > > >what would be the most performant and best way to get
> > > >the longest text of a apple node, and the longest text
> > > >of a orange node?
> > > >
> > > >thanks alot!
> > > >
> > > >ciao!
> > > >florian
> > > >
> > > >
> > > >  XSL-List info and archive:  
http://www.mulberrytech.com/xsl/xsl-list
> > 
> > Rick Taylor
> > XML Developer
> > PPDM Association
> > 
> > 
> >  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 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.