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

Re: position of a child node

Subject: Re: position of a child node
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 15 Nov 2001 22:19:01 GMT
javascript get child node position
>     Actually I thought it was rather clear, but maybe it was not.
well still isn't really:-)


> As I am traversing this tree  with a statement like
> 
> <xsl:template match = "testcase">
   .....

a match pattern in a template doesn't traverse the tree it just executes
a template if you happen to arrive at that node during your traversal
(which you specify with select attributes on apply-templates.)
This difference is important as position() in the template does not
relate to anything in the souce file but to the position in the current
node list formed by ordering the node set of the currently active
apply-templates into document order. So for example if you go
<xsl:apply-templates select=".."/> when you are at a child2 element then 
the template for testcase will run and position() will be 1, for every
test case.

But what I think  number you want is, given


<mainElement>
 <testcase>
  <child1>first text</child1>
  <child2>
    <child21>
        this is the text node for I want which I want to find its position
and it
       contains three dots (...)
    </child21>
  </child2>
</testcase>
<testcase>
  <child1>first text</child1>
  <child2>
    <child21>
       some other text that I don't want
      <child211>
          This is the text node for I which want to find its position and it
          contains three dots (...)
      </child211>
    </child21>
  </child2>
 </testcase>
</mainElement>

to get 3 on the first test case and 4 on the second, is that right?

if so you want the number of descendents of tetscase with teh property
that the marked element follows or is a descendent of the elments being
counted. (incidentally why do you want this number, it seems a very
strange thing to want?)

probably the easiest way is to go
<xsl:for-each select="descendent::*">
 <xsl:if test="contains(.,'...')">
  <xsl:value-of select="position()"/>
 </xsl:if>
</xsl:for-each>

there are certainly more efficient ways (you can look at some general
set difference functions at Jeni's site I think, but teh above is simper
to understand and maintain, but inefficient if there are lots of nodes
after the marked one.

David


_____________________________________________________________________
This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit http://www.star.net.uk/stats.asp or alternatively call
Star Internet for details on the Virus Scanning Service.

 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.