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

Re: finding position() in xpath 1.0

Subject: Re: finding position() in xpath 1.0
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 19 Mar 2007 13:08:10 GMT
Re:  finding position() in xpath 1.0
I think I mis read your requirement. the code I posted works so long as
there is at most one node with test="yes. If you have multiple such
nodes and need to select the preceding cousin of all of them,
Then...

//CELL[@test='yes']/../preceding-sibling::ROW[1]/CELL[position()=count(../following-sibling::ROW[1]/CELL[@test='yes']/preceding-sibling::CELL)+1]

David


<ROWS>
<ROW>
   <CELL id="a"/>
   <CELL id="b"/>   <!-- select this and only this-->
   <CELL id="c"/>
</ROW>
<ROW>
   <CELL/>
   <CELL test="yes"/>
   <CELL/>
</ROW>
<ROW>
   <CELL/>
   <CELL/>
   <CELL/>
</ROW>
<ROW>
   <CELL id="aa"/>
   <CELL id="bb"/>   <!-- select this and only this-->
   <CELL id="cc"/>
</ROW>
<ROW>
   <CELL/>
   <CELL test="yes"/>
   <CELL/>
</ROW>
<ROW>
   <CELL/>
   <CELL/>
   <CELL/>
</ROW>
</ROWS>

  <xsl:template match="/">
    <xsl:copy-of select="//CELL[@test='yes']/../preceding-sibling::ROW[1]/CELL[position()=count(../following-sibling::ROW[1]/CELL[@test='yes']/preceding-sibling::CELL)+1]"/>
  </xsl:template>
</xsl:stylesheet>

$ saxon count.xml count.xsl
<?xml version="1.0" encoding="utf-8"?><CELL id="b"/><CELL id="bb"/>

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.