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

RE: Find the node with maximum elements

Subject: RE: Find the node with maximum elements
From: "Bjorndahl, Brad" <brad.bjorndahl@xxxxxxxxxxxxxxxx>
Date: Mon, 5 Nov 2007 15:02:09 -0500
RE:  Find the node with maximum elements
Hi,

I agree - a nice solution.

But the solution would be even nicer if we had more access to the key.

Once we have the key we can select all elements that have 0 cars, or 1 car, or
6 cars, but not a run-time function of the key use value such as what we want:
the largest value of 'use' in this document. So we do what is shown below -
scan through the elements to find the maximum value even though the
information is _already in the key_. (I doubt that I have the terminology
correct.)

I would like something like:
<xsl:for-each select="key('cars', max())">
<xsl:for-each select="key('cars', sort(ascending))">

or if 'use' is alpha, something like:
<xsl:for-each select="key('carnames', not(contains('xyz'))">

Is this a good addition for XSLT 2.1? It seems to me this allows both
simplified and more efficient code.

Brad.


-----Original Message-----
From: Mukul Gandhi [mailto:gandhi.mukul@xxxxxxxxx]
Sent: November 5, 2007 1:02 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Find the node with maximum elements

Nice solution, Scott.

On 11/5/07, Scott Trenda <Scott.Trenda@xxxxxxxx> wrote:
> This may be better represented with 2.0's grouping facilities, but
> here's the 1.0 solution I'd use to alleviate Mukul's concerns
> (building off Michael's response with <xsl:sort/>):
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
>  <xsl:key name="cars" match="*[Car]" use="count(Car)"/>
>
>  <xsl:template match="Sample">
>
>    <xsl:variable name="max-cars">
>      <xsl:for-each select=".//*[Car]">
>        <xsl:sort select="count(Car)" data-type="number"/>
>        <xsl:if test="position() = last()">
>          <xsl:value-of select="count(Car)"/>
>        </xsl:if>
>      </xsl:for-each>
>    </xsl:variable>
>
>    <xsl:for-each select="key('cars', $max-cars)">
>      <!-- do whatever you'd do with the results here -->
>      <xsl:value-of select="name()"/>
>    </xsl:for-each>
>
>  </xsl:template>
>
> </xsl:stylesheet>
>
> ~ Scott


--
Regards,
Mukul Gandhi

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.