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

RE: in for-each apply-templates doesnot work

Subject: RE: in for-each apply-templates doesnot work
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Tue, 18 Sep 2001 18:12:48 +0100
xslt for each apply templates
> Goal is to select the double datarecords.
> I identify them if attribute1 and attribute2 are equal

This is essentially a grouping problem, where you are only interested in
groups of size 2 or more. As the grouping key is a compound key (it's not
the string-value of a node), take a look at Muenchian grouping, either in
XSLT Programmer's Reference, or at
http://www.jenitennison.com/xslt/grouping.
>
> In XSL I tried to process with "for-each",
> getting the actual position1,
> searching the next matching row,
> getting that position2
>
>       <xsl:variable name="pos1">
>          <xsl:value-of select="position()"/>
>      </xsl:variable>
>
>       <xsl:variable name="pos2">
>          <xsl:apply-templates
> select="following-sibling::row[@attribute1=$value1]"/>
>          <xsl:value-of select="position()"/>
>      </xsl:variable>

The two calls on position() above will return the same result, since they
appear in the same template. You haven't shown us what the template rule for
match="row" actually does, but it doesn't make much difference, the above
code is not going to do anything useful.

A more productive approach would be something like

<xsl:variable name="pos2"
select="count(following-sibling::row[...]/preceding-sibling::*)"/>

but I'm not sure what you want to do with the position once you've got it.

> - position results are 2,4,6.. instead of 1,2,3..

That's because you are processing the whitespace text nodes between the
elements, as well as the elements themselves. Get rid of them using
<xsl:strip-space>.

> - the double row found with apply-templates
> is processed too.

You've lost me here. Fix the other problems first.

Mike Kay


 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.