[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: Midsummer Sun <midsummer.sun@xxxxxxxxx>
Date: Sun, 3 Apr 2005 01:01:41 +0530
select position
Hi David,
  I have a very basic question.

Why this should not work -
<xsl:template match="entry">
  <xsl:value-of select="../../colspec[position()]/@colname"/>

My doubt came because..
If we use 
<xsl:value-of select="../../colspec[2]/@colname"/>
i.e. if we use a static number as predicate of colspec , it expectedly
gets(to my expectation!) the 2nd colspec child of table.

But should'nt this <xsl:value-of select="../../colspec[position()]/@colname"/>
do the same thing? 

If I run this program:
<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
 <xsl:output method="text" />  

 <xsl:template match="/">
   <xsl:apply-templates select="table/row/entry" />
<xsl:template match="entry">
  <xsl:value-of select="../../colspec[position()]/@colname"/>

With XML:
 <colspec colname="c1"/>
 <colspec colname="c2"/>
 <colspec colname="c3"/>
   <entry colname="c1">r1_1</entry>
   <entry colname="c2">r1_2</entry>
   <entry colname="c3">r1_2</entry>

The output is c1c1c1 . i.e. the instruction <xsl:value-of
select="../../colspec[position()]/@colname"/> always picks element
<colspec colname="c1"/> (i.e. 1st one)..

This amazes me.. Can you please clarify the rationale behind the
complex expression you wrote. And why simply [position()] should not

Best regards,

> If you really object to variables
>  <xsl:value-of select="../../colspec[position() = count(current()/preceding-sibling::entry)+1]/@colname"/>
> but that's likely to be slower
> David
> ________________________________________________________________________
> This e-mail has been scanned for all viruses by Star. The
> service is powered by MessageLabs. For more information on a proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk
> ________________________________________________________________________

Current Thread


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.
First Name
Last Name
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.