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

RE: Select nodes with equal position

Subject: RE: Select nodes with equal position
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 2 Apr 2005 20:22:32 +0100
xsl subsequence
> depending on the postion() of a certain node I would like to select 
> another node with the same position.
> It works if I invent a variable.
> But I wonder if there is a way to do it without the use of a variable?

Not if you're using a predicate, because position() inside a predicate is
different from position() outside the predicate.

As DC said, it's much better to make your variable hold the position as a
number rather than as a text node in a result tree fragment: that is, to use
the select attribute.

In fact there's an XSLT 2.0 solution that doesn't require a predicate and
therefore doesn't require a variable:

<xsl:value-of select="../../subsequence(colspec, position(), 1)/@colname"/>

Michael Kay
http://www.saxonica.com/

> 
> 
> XML:
> 
> <table>
>   <colspec colname="c1"/>
>   <colspec colname="c2"/>
>   <colspec colname="c3"/>
>   <row>
>     <entry colname="c1">r1_1</entry>
>     <entry colname="c2">r1_2</entry>
>     <entry colname="c3">r1_2</entry>
>   </row>
> </table>
> 
> 
> XSL:
> <xsl:template match="entry">
>   <xsl:variable name="mypos">
>     <xsl:value-of select="position()"/>
>   </xsl:variable>
>   <xsl:value-of select="../../colspec[position() = $mypos]/@colname"/>
> </xsl:template>
> 
> 
> Best regards and thanks for your comments,
> Norbert Heidbrink

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.