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

Re: Key and/or grouping questions.

Subject: Re: Key and/or grouping questions.
From: "Edward L. Knoll" <ed.knoll@xxxxxxxxxxxxxx>
Date: Thu, 05 Dec 2002 15:39:07 -0700
following sibling position
"Edward L. Knoll" wrote:
> 
> > > I have a set of style sheets which have a sever performance
> > > problem. Distilled (hopefully not diluted past usefulness), I
> > > am processing a
> > > large set of sibling elements a few elements at a time.   I
> > > believe the
> > > problem is with the following statement (which I've
> > > changed/condensed the expression of):
> > >
> > > <xsl:for-each  select="/elements[ (position() &gt;= $Start) and
> > > (position() &lt;= $End) ]">
> > > ...
> > > </xsl:for-each>
> >
> > I suspect it actually starts "//elements", because you can't have more
> > than one element that's a child of the root node. But the fact that
> > position() works suggests that they are siblings. Without seeing your
> > source, the first step might be to change this to /*/elements[...]. The
> > next step would be to create a global variable whose value is
> > /*/elements, and replace the for-each by
> >
> > select="$var[position() ...]
> >
> > > I was referred to a FAQ on grouping and this led me to
> > > attempt to setup
> > > some kind of solution utilizing keys.   Unfortunately, the
> > > XSL reference
> > > I have has no information on <xsl:key> and my favorite FAQ
> > > has a list of topics under keys with no corresponding
> > > content.  Anyway, my XSL processor (Xalan) doesn't like my
> > > key definition.  Is the "use" parameter limited from being a
> > > numerical expressions?
> > >
> > > <xsl:key name="PageKey" match="/gnsl:Results/gnsl:Table/gnsl:Row"
> > >          use="((position() - 1) / $RowsPerPage) + 1)" />
> > >
> >
> > It helps in any XPath expression to balance the parentheses properly.
> >
> > But your problem here is misunderstanding what "position()" means. It
> > means the position of the context node in the sequence of nodes
> > currently being processed. In <xsl:key> it will always be 1.
> >
> > What you want is something like:
> >
> >    use="count(preceding-sibling::*)"
> >
> > But I suspect this may not help you, because it's likely to be very
> > expensive to build this index.
> >
> > I think a better approach would be to restructure your code to use the
> > usual:
> >
> > <xsl:for-each select="xx[position() mod $size = 1]">
> >   ..
> >   <xsl:for-each select=".|following-sibling[position() &lt;= $size]">
> 
> Trying something similar to the nested for-each, excpet my outer
> for-each is somthing similar to the following:
> 
>    <xsl:for-each select="xx[position() = $startPos]">
> 
> I get the line at the starting postion just fine, but I get none of the
> following-sibling elements.  If the outer loop selects one element (or
> even every nth element), are the elements selected by the outer loop
> going to have siblings other than those selected by the outer loop; I'm
> guessing not.  I suspect the inner loop in the algorithm above is going
> to process a number nodes equal to $size, but those nodes will be every
> nth element from the xx where n = $size.
> 
> If I've missed something, please let me know.

Syntax error again; the following works:

  <xsl:for-each select=".|following-sibling::*[position() &lt;= $size]">

-- 
Edward L. Knoll   Phone (work)     : (719)484-2717
                  e-mail (work)    : ed.knoll@xxxxxxxxxxxxxx
                  e-mail (business): eknoll@xxxxxxxxxx
                  e-mail (personal): edward@xxxxxxxxxxx

 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.